admin管理员组文章数量:1401143
Here is the json data
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',
}];
From this how can i filter only mode:daily
, mode:weekly
as below.I have to remove other values except mode:daily``mode:weekly
var myArray = [{
id: '45',
mode: 'weekly',
os: 'VM-WIN7-32'
}, {
id: '67',
mode: 'daily',
os: 'VM-WIN7-32-1',
}];
Here is the json data
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',
}];
From this how can i filter only mode:daily
, mode:weekly
as below.I have to remove other values except mode:daily``mode:weekly
var myArray = [{
id: '45',
mode: 'weekly',
os: 'VM-WIN7-32'
}, {
id: '67',
mode: 'daily',
os: 'VM-WIN7-32-1',
}];
Share
Improve this question
edited Feb 28, 2014 at 10:28
Abbas
14.4k6 gold badges42 silver badges75 bronze badges
asked Jan 8, 2014 at 9:09
SushSush
1,4579 gold badges27 silver badges51 bronze badges
1
- possible duplicate of remove duplicates from json array and bine its id's using node.js – Ilan Frumer Commented Jan 8, 2014 at 9:14
1 Answer
Reset to default 6Use the Array#filter method.
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');
});
JSFIDDLE
本文标签: javascriptFilter values from a json data using nodejsStack Overflow
版权声明:本文标题:javascript - Filter values from a json data using node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744250195a2597216.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论