3

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',
    }];
1

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.