数组问题?
如何将 value = [‘1’, ‘2’, ‘3’]这样的数组转化为 value = [{name0:‘1’,name1: ‘2’,name2:‘3’}]
3 回复
let value = [
[‘1’, ‘2’, ‘3’],
[‘5’, ‘6’, ‘7’]
]
var arr = []
var select = {};
var arr1 = {};
var name = ‘’
console.log(value.length)
for (var j = 0; j < value.length; j++) {
for (var i = 0; i < value[j].length; i++) {
var key = ‘name’ + i;
var zhi = value[j][i]
select[key] = zhi
}
arr.push(select)
arr1 = {
arr3: arr
}
console.log(arr1)
}
想再请教一下上面的代码如何修改才能将0那里的输出是{name0:‘1’,name1:‘2’,name2:‘3’},就是不要别覆盖