2 回答
TA贡献1810条经验 获得超5个赞
一种单行解决方案,带有Array.filter()和Array.map()。
const columns = [
{
data: "id",
searchable: false
},
{
data: "first_name",
searchable: true
},
{
data: "last_name",
searchable: true
}
];
const filter = {
target: columns,
};
const result = columns.filter(column => column.searchable).map(column => column.data);
filter.target = result;
console.log(filter);
TA贡献1836条经验 获得超4个赞
const columns = [{
data: "id",
searchable: false
},
{
data: "first_name",
searchable: true
},
{
data: "last_name",
searchable: true
}
];
let filter = {
target: []
};
for (let i = 0; i < columns.length; i++) {
if (columns[i].searchable) {
filter.target.push(columns[i].data);
}
}
console.log(filter);
添加回答
举报