JavaScript nested JSON of same name JavaScript nested JSON of same name json json

JavaScript nested JSON of same name


You could take a recursive depth-first search for the nested object.

function depthFirst(object) {    return [...(object.nest ? depthFirst(object.nest) :[]), object.func];}var data = { func: "sprint", nest: { func: "walk", nest: { func: "run" } } };console.log(depthFirst(data));