gpt4 book ai didi

javascript - 如何从对象数组中获取对象属性的非空值?

转载 作者:行者123 更新时间:2023-12-02 01:49:00 25 4
gpt4 key购买 nike

<分区>

在从服务器接收到的对象数组中,我只想处理和检索对象中属性的非空值。我怎样才能在我的函数中改变它??

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',
}]

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com