Javascript examples for Array Operation:Array Nest
Update nested attributes in a JavaScript object
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//from w w w . j ava2s .c o m var data = {level1: {level2 : 'test' }}; var parents = 'level1/level2'.split('/'); var target = data; for(var i=0; i<parents.length-1; i++){ target = target[parents[i]]; } target[parents[i]] = 'new value'; console.log( data.level1.level2 ); }); </script> </head> <body> </body> </html>