json - Modify a JavaScript Object while iterating its properties -


can javascript implement pass-by-reference techniques on function call? see, have json below , need traverse node. while traversing, if current item object , contains key nodes, must add property isparent: true that exact same item. i'm having difficulty on creating traversal function such feature, , tried search traversal functions, found returns new json object instead of changing exact json being processed.

var default_tree = [     {         text: "applications",         nodes: [             {                 text: "reports data entry",                 nodes: [                     { text: "other banks remittance report" },                     { text: "statement of payroll deduction" },                     ...                 ]             },             {                 text: "suspense file maintenance",                 nodes: [                     { text: "banks individual remittances" },                     { text: "employers / banks employers" },                     ...                 ]             }         ]     },     {         text: "unposted transactions",         nodes: [             { text: "unposted borrower payments"},             { text: "unposted cmp payments"}         ]     },     { text: "maintenance" },     {         text: "reports",         nodes: [             {                 text: "daily reports",                 nodes: [                     {                         text: "list of remittance reports",                         nodes: [                             { text: "banks" },                             ...                             {                                 text: "employers-lbp",                                 nodes: [                                     { text: "employers-zonal" }                                 ]                             },                         ]                     },                     ...                 ]             },             ...         ]     } ] 

considering have traversal function:

function traverse(json_object) {     // perform traversal here }  traverse(default_tree) 

after runs traverse function, default_tree's value remain same unless like:

default_tree = traverse(default_tree) 

can me create iterator really alter object being processed while iterating, instead of returning new object?

please check one

var default_tree = [....] //array  function traverse(arrdefaulttree){     arrdefaulttree.foreach(function(val,key){          if(val.hasownproperty("nodes")){             val.isparent = true;             traverse(val.nodes);          }     })  }  traverse(default_tree); console.log(default_tree); 

hope helpful.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -