同时保持记录不从循环数组中取出空字符串? [英] Remove empty strings from array while keeping record Without Loop?
问题描述
这个问题在这里问:
<一href=\"http://stackoverflow.com/questions/18113243/remove-empty-strings-from-array-while-keeping-record-of-indexes-with-non-empty-s\">Remove从阵列空字符串,同时保持与非空字符串的索引记录
如果你注意到给出@Baz奠定出来;
我,AM,,仍然,这里,,人
的,并从这个我想产生以下两个数组:的
我,AM,仍然,这里,人
所有的答案的这个问题提到循环的一种形式。
我的问题:是否有可能为删除所有首页
ES与空
字符串
没有任何循环? ...有没有其他的替代除了遍历数组?
可能有些正则表达式
或者一些的jQuery
,我们不知道的?
所有的答案和建议是非常AP preciated。
VAR ARR = [我,AM,,仍然,这里, , 人]
// ARR = [我,AM,,仍然,这里,,人]
ARR = arr.filter(布尔)
// ARR = [I,上午,仍然,这里,人]
<一个href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter\"><$c$c>filter$c$c>文档
// ARR = [我,AM,,仍然,这里,,人]
ARR = arr.filter(V =&GT;!V ='');
// ARR = [I,上午,仍然,这里,人]
<一个href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions\">Arrow功能文档
This question was asked here: Remove empty strings from array while keeping record of indexes with non empty strings
If you'd notice the given as @Baz layed it out;
"I", "am", "", "still", "here", "", "man"
"and from this I wish to produce the following two arrays:"
"I", "am", "still", "here", "man"
All the Answers to this question referred to a form of looping.
My question: Is there a possibility to remove all index
es with empty
string
without any looping? ... is there any other alternative apart from iterating the array?
May be some regex
or some jQuery
that we are not aware of?
All answers or suggestions are highly appreciated.
var arr = ["I", "am", "", "still", "here", "", "man"]
// arr = ["I", "am", "", "still", "here", "", "man"]
arr = arr.filter(Boolean)
// arr = ["I", "am", "still", "here", "man"]
// arr = ["I", "am", "", "still", "here", "", "man"]
arr = arr.filter(v=>v!='');
// arr = ["I", "am", "still", "here", "man"]
这篇关于同时保持记录不从循环数组中取出空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!