I have an array of objects like the following:
organisationData = [
{
"id": -516538792,
"label": "name",
"value": "Apple",
"key": "name"
},
{
"id": -586565959,
"label": "field",
"value": "IT",
"key": "field"
},
{
"id": 2081552018,
"label": "name",
"value": "Microsoft",
"key": "name"
},
{
"id": -1094152060,
"label": "field",
"value": "IT",
"key": "field"
}
]
I need to split this array so that it follow the following format:
organisations = [
{
"name": "Apple",
"field": "IT"
},
{
"name": "Microsoft",
"field": "IT"
}
]
I can create a new array that follows the correct format but each 'company' is part of the same array and I'd like to split them out, how do I modify the following?:
let organisationData = [.....]
let organisations = [];
for (org of organisationsData) {
_org = [];
_org[org.key] = org.value;
organisations.push(_org);
};
"name": "Apple"is not an array element and[ "name": "Apple", "field": "IT" ]is not a valid array. Did you mean to use{and}?