var peopleArray=[] var peopleobj={jiangyx: "姜艳霞", yeluosen: "叶落森"} for(let i in peopleobj){ debugger var obj={ nickname:i, realName:peopleobj[i] } peopleArray.push(obj) } console.log(peopleArray)
1. 前言 首先,当JS对象是键值对的情况时(Json对象),因为数组时以数字为索引的,所以只能把JS对象中的Key或者Value组成数组使用. 2. 样例如下: var obj={"one":"I am 1","two":"I am 2"}; var arr = Object.getOwnPropertyNames(obj); //arr=["one", "two"] var arr2
需求是将b根据a的值替换对象中的key值 let a = ["code","name","date","font"]; let b = [{1:2,2:3,3:4},{1:2,2:3,3:4},{1:2,2:3,3:4}]; //[{'code':2,'name':3,'date':4},{'code':2,'name':3,'date':4},{'code':2,'name':3,'date':4}]; let c = b.