1

How to collect array of objects in javascript, example i have this array in this case :

var abc = [{"name": "udin", "checked": true}, {"name": "kabayan": "checked": true}, {"name": "hebring"}];

how to get result like this :

abc = [{"name": "udin", "checked": true}, {"name": "kabayan": "checked": true}];

i'm just want to showing only element with "checked" == true

tardjo
  • 1,594
  • 5
  • 22
  • 38

1 Answers1

7

Use js native array filter function like bellow

abc = abc.filter(function(obj){
    return obj.checked;
});
console.log(abc);

It will give you expected output.

Mritunjay
  • 25,338
  • 7
  • 55
  • 68