循环数组赋值给对象并push到数组中

初始数据:


转化为


代码:

 const data="初始数据"
                const arr=[]

                Object.keys(data).forEach((key)=>{
                    const item={
                        x:key,
                        y:data [key] 
                    } 
                    arr.push(item)
                })

转换结果:


你可能感兴趣的:(循环数组赋值给对象并push到数组中)