2016-10-01 7 views
0

複数単語のエントリからなる配列から1つの単語のエントリを削除する方法を知っておく必要があります。ここでは、配列の例です:配列から単一単語のエントリを削除する

INPUT:

[ "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(' ')) 
 
)

関連する問題