I have a lot of values I need to extract from a JSON object called results
. I have stored the keys I care about in another object myKeys
.
How can I use the values from myKeys
as the selector in results
? Ultimately I want the data in results.array1.array2.key
, results.array1.anotherThing.key
, etc.
const myKeys = {
key1: '.array1.array2.key',
key2: '.array1.anotherThing.key',
key3: '.array1.somethingElse.array2.key'
}
for (let [key, value] of Object.entries(myKeys)){
let data = {name: key, results: results[value]}
}