这里是json数据
var myArray = [{
id: '71',
os: 'VM-WIN7-64'
}, {
id: '45',
mode: 'weekly',
os: 'VM-WIN7-32'
}, {
id: '37',
os: 'VM-WIN7-64',
}, {
id: '67',
mode: 'daily',
os: 'VM-WIN7-32-1',
}];
从这里我如何才能过滤 mode:daily
, mode:weekly
如下。我必须删除除 mode:daily``mode 之外的其他值:每周
var myArray = [{
id: '45',
mode: 'weekly',
os: 'VM-WIN7-32'
}, {
id: '67',
mode: 'daily',
os: 'VM-WIN7-32-1',
}];
最佳答案
使用 Array#filter方法。
The filter() method creates a new array with all elements that pass the test implemented by the provided function.
myArray = myArray.filter(function(o){
return (o.mode === 'weekly' || o.mode === 'daily');
});
关于javascript - 使用 node.js 从 json 数据中过滤值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20991169/