I would like to know what is the best way to update the member of the multilevel object collection in JavaScript
Here is the simplified version of my collection:
You must recursively descend your tree structure searching for the object with the target "id" and replace its text. For example:
function updateObjectByID(obj, id, text) {
if (!obj) return;
if (obj.id === id) {
obj.text = text;
} else if ((typeof(obj)==='object') && (obj.constructor===Array)) {
for (var i=0; i
However, this solution can be optimized by tree pruning.