How to extract only numbers from an array in JavaScript

1 Answer

0 votes
const arr = [8, 'javascript', 90, null, 537];

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

console.log(onlyNumbers); 


  
  
  
  
/*
run:

[8, 90, 537]
  
*/

 



answered May 9, 2022 by avibootz

Related questions

...