var data = [
{key:'raz', cells:[{val: '1'},{val:'razoviy'}]},
{key:'dva', cells:[{val: '2'},{val:'vtoroy'}],children:[
{key:'poddva', cells:[{val: '2'},{val:'podvtoroy'}],children:
[{key:'podpoddva', cells:[{val: '2'},{val:'podpodvtoroy'}]},{key:'raz', cells:[{val: '1'},{val:'raz'}]}]
},
{key:'poddvadva', cells:[{val: '2'},{val:'podvtoroyvtoroy'}]}
]},
{key:'tri', cells:[{val: '3'},{val:'trtiy'}]}
]
var adres = ['dva','poddva','raz']
var newDataCells = [{val: '1.0'},{val:'raz raz, est svyaz'}]
var data = [
{key:'raz', cells:[{val: '1'},{val:'razoviy'}]},
{key:'dva', cells:[{val: '2'},{val:'vtoroy'}],children:[
{key:'poddva', cells:[{val: '2'},{val:'podvtoroy'}],children:
[{key:'podpoddva', cells:[{val: '2'},{val:'podpodvtoroy'}]},{key:'raz', cells:[{val: '1'},{val:'raz'}]}]
},
{key:'poddvadva', cells:[{val: '2'},{val:'podvtoroyvtoroy'}]}
]},
{key:'tri', cells:[{val: '3'},{val:'trtiy'}]}
]
var adres = ['dva','poddva','raz']
var newDataCells = [{val: '1.0'},{val:'raz raz, est svyaz'}]
var lastMath
Object.traverse(data, function(node, value, key, path, depth) {
if(typeof value == 'object' && value.key){
let indexAdres = 0;
if(depth > 0)
indexAdres = depth/2
if(value.key == adres[indexAdres])
lastMath = value
}
});
lastMath.cells = newDataCells
console.log(data)
var data = [
{key:'raz', cells:[{val: '1'},{val:'razoviy'}]},
{key:'dva', cells:[{val: '2'},{val:'vtoroy'}],children:[
{key:'poddva', cells:[{val: '2'},{val:'podvtoroy'}],children:
[{key:'podpoddva', cells:[{val: '2'},{val:'podpodvtoroy'}]},{key:'raz', cells:[{val: '1'},{val:'raz'}]}]
},
{key:'poddvadva', cells:[{val: '2'},{val:'podvtoroyvtoroy'}]}
]},
{key:'tri', cells:[{val: '3'},{val:'trtiy'}]}
]
var newDataCells = [{val: '1.0'},{val:'raz raz, est svyaz'}]
var obj = data.find(val => val.key == 'dva')
obj.cells = newDataCells;
console.log(data);