Remove Whitespace-only Array Elements

后端 未结 8 878
悲&欢浪女
悲&欢浪女 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:52

    Another filter based variation - reusable (function)

        function removeWhiteSpaceFromArray(array){
        return array.filter((item) => item != ' ');
    }
    

提交回复
热议问题