0

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

akilaF_do
  • 1
  • 1

1 Answers1

0

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);
timnavigate
  • 741
  • 4
  • 12
  • 23