需求是要两个数组,变成对象的形式。代码如下
let nameArr = ['张三','李四','王五']
let sexArr = ['男','女','男']
let newObject =nameArr.map((item,index)=>{
return {
name:item,
url:sexArr[index]
}
})
console.log(newObject )
let nameArr = ['张三','李四','王五']
let sexArr = ['男','女','男']
let newObject =nameArr.map((item,index)=>{
return {
name:item,
url:sexArr[index]
}
})
console.log(newObject )
本文标题:es6 将两个数组合并成键值对
本文链接:https://www.haomeiwen.com/subject/magyyltx.html
网友评论