I feel tantalizingly close here. Scenario: I have a JSON sent in a message that looks something like this:
{"objects": {
"object_name1":{
"name":"object_name1",
"otherData":"some other data"
},
{"object_name2":{
"name":"object_name2",
"otherData":"some more data"
}
}}
As you can see, the objects are not in an array. I created an array containing each Object's string name using the Object.keys function and then created another array which contains the objects that I want using an if statement, which leads to my current question:
How can I create an array of objects using the string values (the object keys) contained in the array I have created?
I've tried something like this:
filteredKeyArray = ['object_name1','object_name2'];
newObjArray = [];
for(i in filteredKeyArray){
for(key in objects){
newObjArray.push(objects[i[key]]);
}
}
But the newObjArray is just displaying all undefined. Ideally the newObjArray displays something like this:
[{"object_name1":{...}},{"object_name2":{...}}]
Thoughts?
}, {part - objects have key-value pairs, not just plain values