How to extract only numbers from an array in TypeScript

1 Answer

0 votes
const arr = [7, 'typescript', 95, null, 89873];

const onlyNumbers = arr.filter(element => typeof element === 'number');

console.log(onlyNumbers); 


  
  
  
  
/*
run:

[7, 95, 89873] 
  
*/

 



answered May 9, 2022 by avibootz
...