如何在javascript中收集对象数组[重复]

时间:2022-11-29 22:39:09

This question already has an answer here:

这个问题在这里已有答案:

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

如何在javascript中收集对象数组,例如我在这种情况下有这个数组:

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

我只想显示“checked”== true的元素

1 个解决方案

#1


5  

Use js native array filter function like bellow

使用js本机数组过滤器功能,如下面

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

It will give you expected output.

它会给你预期的输出。

#1


5  

Use js native array filter function like bellow

使用js本机数组过滤器功能,如下面

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

It will give you expected output.

它会给你预期的输出。