本文介绍了包含Java中特定符号或单词的过滤器数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想在过滤我的数组时寻求帮助,我有一个包含单词的数组列表,但我想过滤掉带有符号(#")的单词以在数组上删除
Hello I would like to ask for help on filtering my Array currently I have a list of array that contains words but I want to filter out those with symbol ("#") to be remove on the array
function InitializeV3() {
var req = SymbolList; //obj with symbol property
for (var i = 0; i < req.lenght; i++) {
if (req[i].smybol.includes("#")) {
req.splice(req[i], 1);
}
}
console.log(req);
};
推荐答案
对于简单的数组,您可以使用filter方法来做到这一点:
For a simple array you can do it like this with the filter method:
var req = ['test','#test1','#test2','test3','test4'];
var result = req.filter(item => !item.includes("#"));
console.log(result);
如果您有对象数组:
var req = [{symbol: 'test'},{symbol: '#test1'},{symbol: '#test2'},{symbol: 'test3'},{symbol: 'test4'}]
var result = req.filter(item => !item.symbol.includes('#'));
console.log(result);
这篇关于包含Java中特定符号或单词的过滤器数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!