Since using array.splice modifies the array in-place, how can I remove all whitespace-only elements from an array without throwing an error? With PHP we have preg_grep but I
const words = ['spray', 'limit', 'elite', 'exuberant', ' ', '']; const result = words.filter(word => word.trim().length > 0); console.log(result);
Here's another approach.
var data = JSON.parse(arrayval.split(/\s/).join(''));