gpt4 book ai didi

javascript - 我如何将数组插入值匹配的其他数组?

转载 作者:行者123 更新时间:2023-11-30 16:21:40 25 4
gpt4 key购买 nike

 var cols = [
{id: 1, title: 'First Column', tasks:[] },
{id: 2, title: 'Second Column', tasks:[] },
{id: 3, title: 'Third Column', tasks:[] }
];

var tasks = [
{id: 1, title: 'Bla bla project', column: 1},
{id: 2, title: 'Hip Hop project', column: 1}
]

我如何循环遍历任务变量并将它们插入匹配列 ID 的 cols 数组?如果没有 jquery,这可能吗?

最佳答案

这样试试

cols.map(function(col){
col.tasks=tasks.filter(function(task){ return task.column == col.id; });
})

DEMO

关于javascript - 我如何将数组插入值匹配的其他数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34646403/

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