扫码关注官方订阅号
如何把list数组里每一个object的id键值对加到brandList数组的每一个object里?
闭关修行中......
这样?
list.forEach(function(item, index){ item.brandList.forEach(function(brandItem, brandIndex){ brandItem.id = item.id; }); });
list.forEach(listItem => { listItem.brandList.forEach(brandListItem => { brandListItem.id = listItem.id }) })
两个循环就好了 第一个循环拿到id 第二个循环把id添加进去,基本的数据操作嘛
你真是比我都懒那
for(var i = 0;i<list.length;i++){ var brandList = list[i]['brandList'] for(var j = 0;j<brandList.length;j++){ brandList[j]['id'] = list[i]['id'] } }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
这样?
两个循环就好了 第一个循环拿到id 第二个循环把id添加进去,基本的数据操作嘛
你真是比我都懒那