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