To by mělo iterovat objekt
function generateId() {
// you'll have to write this yourself
}
function addId(obj) {
if (Object.prototype.toString.call(obj).indexOf('Array') >= 0) {
obj.forEach(function(item) {
item.id = item.id || generateId();
addId(item);
});
}
else if (typeof obj == 'object') {
Object.keys(obj).forEach(function(key) {
addId(obj[key]);
});
}
}
použití
addId(yourObject);