【发布时间】:2026-01-18 16:15:01
【问题描述】:
在从服务器接收到的对象数组中,我想只处理和检索对象中属性的非空值。如何在我的函数中更改它??
const arr = [{
text01 : 'name',
text02 : 'email@gmail.com',
text03 : '010-1234-5678',
text04 : 'adress1',
text05 : 'adress2',
text06 : null,
text07 : null,
text08 : null,
},
{ text01 : 'name1',
text02 : 'email2@gmail.com', text03 : '010-1255-5148',
text04 : 'adress3',
text05 : 'adress4',
text06 : null,
text07 : null,
text08 : null,
}]
getDataArr(arr) {
arr.forEach(item => {
const aaa = [];
for (let key in item) {
if (item[key] !== null) {
const value = item[key];
aaa.push({ key, value });
}
}
console.log(aaa); });
获取值为
const arr = [{ text01 : 'name',
text02 : 'email@gmail.com',
text03 : '010-1234-5678',
text04 : 'adress1',
text05 : 'adress2'
},
{
text01 : 'name1',
text02 : 'email2@gmail.com', text03 : '010-1255-5148',
text04 : 'adress3',
text05 : 'adress4',
}]
【问题讨论】:
标签: javascript arrays object