En utilisant une fonction de générateur, vous pouvez itérer sur des valeurs de clés profondes.
function * deepEntries(obj) {
for(let [key, value] of Object.entries(obj)) {
if (typeof value !== 'object')
yield [key, value]
else
for(let entries of deepEntries(value))
yield [key, ...entries]
}
}
const dictionary = {
"data": [
{"id":"0","name":"ABC"},
{"id":"1","name":"DEF"}
],
"images": [
{"id":"0","name":"PQR"},
{"id":"1","name":"xyz"}
]
}
for(let entries of deepEntries(dictionary)) {
const key = entries.slice(0, -1).join('.')
const value = entries[entries.length-1]
console.log(key, value)
}