0

given an array [{"id":"66859","value":"Discontinued"},{"id":null,"value":null}], i want to remove the objects that have id value of null.

is it possible using underscore? or any other javascript method

2 Answers 2

3

You can use a reject function in underscore.js. It returns array without the object you want to delete.

 arr = _.reject(arr, function(item){ return (item.id === null || item.id === ??); });
Sign up to request clarification or add additional context in comments.

Comments

2

Very simple with Array.prototype.filter()

var arr = data.filter((item)=>{return item.id});

2 Comments

Hooray for recommending an ES5 standard feature!
you could even write it like const arr = data.filter( item => item.id )

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.