How to remove all empty strings from an array in TypeScript

1 Answer

0 votes
let arr = ['typescript', '', '', 'c', '', 'c++', '', '', 'php'];

arr = arr.filter(element => { return element !== ''; });

console.log(arr);




/*
run:

["typescript", "c", "c++", "php"] 

*/

 



answered Feb 17, 2022 by avibootz
...