Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter values from a json data using node.js

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',
    }];
like image 238
Sush Avatar asked Nov 28 '25 18:11

Sush


1 Answers

Use 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

like image 139
dcodesmith Avatar answered Nov 30 '25 06:11

dcodesmith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!