close
轉自 https://stackoverflow.com/questions/37224085/how-to-remove-key-from-array-of-object
--
Q:
I have Array objects like below , How to convert this format into Array of objects and remove key.
{
"9417702107": {
"name": "Sunny",
"phone": "9417702107",
"exists": true
},
"8826565107": {
"name": "Gurwinder",
"phone": "8826565107",
"exists": true
}
}
How to convert this into below format using javascript:
[{
"name": "Sunny",
"phone": "9417702107",
"exists": true
}, {
"name": "Gurwinder",
"phone": "8826565107",
"exists": true
}]
A:
Use a simple loop:
array = [];
for (var key in obj) {
array.push(obj[key]);
}
As in the other answer, there's no guarantee that the elements of the array will be in the same order as in the object.
--
全站熱搜
留言列表