2016-10-01 37 views
0

我需要知道如何从包含多个词条目的数组中删除单个词条目。这里是数组的一个例子:删除数组中的单个词条

输入:

[ "Off the bloody wall", "who?", "That sounds familiar" , "lol", "what the hell" ] 

所需的输出

[ "Off the bloody wall", "That sounds familiar" , "what the hell" ] 

我可以把一个多级解决方案,这一点,但也许有人在这里知道快速的单行jQuery解决方案吗?

回答

2

您可以使用Array.protype.filter删除不通过谓词函数的元素,并使用String.prototype.match来测试字符串是否匹配。在这种情况下,如果没有空间,我们会过滤掉该属性。

const arr = [ "Off the bloody wall", "who?", "That sounds familiar" , "lol", "what the hell" ] 
 

 
console.log(
 
    arr.filter(item => item.match(' ')) 
 
)