I have following json object :
"records": { "abc": { "id": "1", "code": "A", "iId": "2", }, "xyz": { "id": "1", "code": "B", "iId": "2", } }
I want to get code values and insert them into a new array. How can I achieve it ? Thanks in advance
I have following json object :
"records": { "abc": { "id": "1", "code": "A", "iId": "2", }, "xyz": { "id": "1", "code": "B", "iId": "2", } }
I want to get code values and insert them into a new array. How can I achieve it ? Thanks in advance
Let's try code below:
let obj = {
"records": {
"abc": {
"id": "1",
"code": "A",
"iId": "2",
},
"xyz": {
"id": "1",
"code": "B",
"iId": "2",
}
}
};
let arr = [];
for (let key in obj) {
for (let subkey in obj[key]){
arr.push(obj[key][subkey]['code']);
}
}
console.log(arr);