How to remove only strings from existing array in Node.js

1 Answer

0 votes
const array = [231, 'javascript', 'node.js', 344, 'typescript', 416, 539];
 
for (let i = array.length - 1; i >= 0; i--) {
    if (typeof array[i] === "string") {
        array.splice(i, 1);
    }
}
 
console.log(array);
  
  
  
  
/*
run:
  
[ 231, 344, 416, 539 ]
  
*/

 



answered Jun 6, 2022 by avibootz
...