比如有个数组 是数字组成需要得格式是下标加值得键值对格式怎么操作
var a = [0,1,2,3]
需要得格式是
[{0:0},{1:1}......]
const a = [0, 1, 2, 3];
const res = a.map((cur, index) => ({ [index]: cur }));
console.log(res);
一分钟掌握js中的map方法:https://blog.csdn.net/weixin_43877799/article/details/119679268
let a = [0, 1, 2, 3]
let b = a.map((item, index) => ({[index]: item}))
let newArr = []
arr.forEach(ele=>{
newArr.push({
ele:ele
})
})
console.log(newArr)