js多层数组如何转换?
原数组:
arr1 = [
{
checked:false,
fileList:[
{
author: "ad",
fileName: "工作的通知(1) - 副本.docx",
isArchive: "yes",
version: "1"
},
{
author: "ad2",
fileName: "工作的通知(1) - 副本.docx",
isArchive: "yes",
version: "2"
},
{
author: "ad3",
fileName: "工作的通知(1) - 副本.docx",
isArchive: "yes",
version: "3"
},
]
},
{
checked:false,
fileList:[
{
author: "cj",
fileName: "工作的通知(2) - 副本.docx",
isArchive: "yes",
version: "1"
},
{
author: "cj2",
fileName: "工作的通知(2) - 副本.docx",
isArchive: "yes",
version: "2"
},
]
}
]
前端想将原数组转换成这种:
arr2= [ {
checked:false,
author: "ad",
fileName: "工作的通知(1) - 副本.docx",
isArchive: "yes",
version: "1"
},
{
checked:false,
author: "ad2",
fileName: "工作的通知(1) - 副本.docx",
isArchive: "yes",
version: "2"
},
{
checked:false,
author: "ad3",
fileName: "工作的通知(1) - 副本.docx",
isArchive: "yes",
version: "3"
},
{
checked:false,
author: "cj",
fileName: "工作的通知(2) - 副本.docx",
isArchive: "yes",
version: "1"
},
{
checked:false,
author: "cj2",
fileName: "工作的通知(2) - 副本.docx",
isArchive: "yes",
version: "2"
},
]
请问使用js方法如何转换啊?
回答:
let arr2 = [];arr1.forEach(e=>{
const { checked,fileList } = e;
fileList.forEach(file=>{
file.checked = checked;
arr2.push(file)
})
})
以上是 js多层数组如何转换? 的全部内容, 来源链接: utcz.com/p/935446.html