Delete Nested Javascript Object
I have been trying to delete a nested object from a JavaScript object, with no success and have not been able to find the correct answer through searching previous posts. Here is
Solution 1:
You need a recursive function to delete the property.
var myobj = {
"children": [
{
"name": "albuterol ",
"children": [
{
"name": "albuterol - fluticasone ",
"children": [
{
"name": "prednisone ",
"children": [
{
"name": "dexamethasone ",
"children": [],
"size": 1,
"colname": "CONCEPT_NAME.4"
}
],
"size": 3,
"colname": "CONCEPT_NAME.3"
}
],
"size": 4,
"colname": "CONCEPT_NAME.2"
}]}]}
functiondeleteColnameRecursive(obj){
delete obj.colnameif(obj.children){
for(var i=0;i<obj.children.length;i++)
deleteColnameRecursive(obj.children[i]);
}
}
deleteColnameRecursive(myobj);
console.log(myobj);
Post a Comment for "Delete Nested Javascript Object"