I am calling an API and got a response an an object in the following form. I would like to append the objects to an array in order to iterate them later.
Using push I got a list of strings == ['Account','AccountName','AccountServiceHomepage']
I would like to push the entire object to the array so for x[0] I get Account as an object not as a string.
Does anyone have a clue?
Snippet
let properties = {
Account: {
label: 'Account',
key: 'Account',
description: { en: '' },
prefLabel: { en: 'test' },
usageCount: '0'
},
AccountName: {
label: 'AccountName',
key: 'AccountName',
description: { en: '' },
prefLabel: { en: '' },
usageCount: '0'
},
AccountServiceHomepage: {
label: 'AccountServiceHomepage',
key: 'AccountServiceHomepage',
description: { en: '' },
prefLabel: { en: '' },
usageCount: '0'
}
}
x = [];
for (i in properties) {
x.push(i);
};
console.log(x);
4
Answers
You can convert object to an array (ignoring keys) like this:
Try this: