Home > front end >  Could you tell me how to put the bosses, a key and the value in the array object as the value assign
Could you tell me how to put the bosses, a key and the value in the array object as the value assign

Time:10-07

How to put the key in an array object and value as the value assigned a new key become a new array object
As with the map can be realized, but small white not, consult

[{completed: 0}, {momentum cargo: 15}, {non-payment: 5}, {is processing: 1}]
======="
======="
Value: [{5, name: 'not paying'}, {value: 15, name: 'momentum goods'},
{value: 1, name: 'being processed'}, {value: 0, name: 'completed'}]

CodePudding user response:

 
<script>
Var data=https://bbs.csdn.net/topics/[{completed: 0}, {momentum cargo: 15}, {non-payment: 5}, {is processing: 1}]
Var arr=[]
Data. The forEach (item=& gt; {
In item) for (var k {
Arr. Push ({name: k, value: item [k]})
}
})
The console. The log (arr)
</script>

CodePudding user response:

 
Var arr=[{completed: 0}, {momentum cargo: 15}, {non-payment: 5}, {is processing: 1}]
Var resArr=arr. The map (item=& gt; ({
Value: the Object values (item) [0],
Name: Object. Keys (item) [0]
}))
The console. The log (JSON. Stringify (resArr, null, 4))

CodePudding user response:

Could you tell me how to do, in turn, should
?
  • Related