JavaScript数组过滤:筛选status为1的元素
在JavaScript中,我们可以使用'filter()'方法来过滤数组。根据给出的条件,我们可以使用以下代码过滤status为1的对象:
const data = [
{
build: '5',
delFlag: false,
deviceType: 'camera',
deviceTypeName: '枪式摄像机',
floor: '14',
height: '56',
id: '261',
ip: '10.11.6.1',
latitude: '0.000609',
longitude: '-0.00004',
name: '楼顶-东侧楼梯',
status: '0'
}
// 其他对象...
];
const filteredData = data.filter(obj => obj.status === '1');
console.log(filteredData);
在上面的代码中,'filter()'方法将会返回一个新的数组,其中包含了满足条件'obj.status === '1''的对象。
原文地址: https://www.cveoy.top/t/topic/p1JV 著作权归作者所有。请勿转载和采集!