2 回答

TA貢獻(xiàn)1810條經(jīng)驗 獲得超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貢獻(xiàn)1836條經(jīng)驗 獲得超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);
添加回答
舉報