var object = {'笔':'2','本':'4',}
var arr=[]
for(var index in object){
console.log(index) //笔 本
console.log(object[index])// 2 4
var obj ={}
obj.name = index
obj.num = object[index]
arr.push(obj)
}
console.log(arr)
2.把数组中的字段单独拿出来
arr = [{deptname:'11',num:1},{deptname:'22',num:2},{deptname:'33',num:3}]
arr2 = arr.map(item =>{
return item.deptname
})
输出 --------['11','22','33']
arr3 = arr.map(item =>{
return {
deptname : item.deptname
}
})
输出 --------0:{deptname:'11'}
1:{deptname:'22'}