Skip to content

Instantly share code, notes, and snippets.

@shermanluong
Created September 5, 2018 19:18
Show Gist options
  • Save shermanluong/d1dec0b6045c44fe68041927e2ae3411 to your computer and use it in GitHub Desktop.
Save shermanluong/d1dec0b6045c44fe68041927e2ae3411 to your computer and use it in GitHub Desktop.
Javascript object nest to array if there is childs
function objToArry(obj, ret=[]) {``
for(var key1 in obj){
ret.push(childToArray(obj[key1]))
}
return ret;
}
function childToArray(obj) {
if(JSON.stringify(obj['children']) === "{}")
obj['children'] = [];
else
obj['children'] = objToArry(obj['children']);
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment