Remove Whitespace-only Array Elements

后端 未结 8 900
悲&欢浪女
悲&欢浪女 2020-12-08 17:30

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

8条回答
  •  遥遥无期
    2020-12-08 17:59

    a="remove white spaces"

    a.split(' ').join('').split('');
    

    It returns an array of all characters in {a="remove white spaces"} with no 'space' character.

    You can test the output separately for each method: split() and join().

提交回复
热议问题