I have recursivity problem when trying to stringify an object.
I wonder if anyone have a tip to know what is the current depth when iterating trough key -> value in the replacer ? I want to replace a reference by its ID, but only when I'm at a specific depth.
Here is a minimalist object to give an exemple :
var a = {
id: 'idOfA',
linkedItems: []
};
var b = {
id: 'idOfB',
linkedItems: []
};
var c = {
id: 'idOfC',
linkedItems: []
};
a.linkedItems.push({
from: 0,
to: 0,
item: b
});
b.linkedItems.push({
from: 0,
to: 0,
item: a
}, {
from: 0,
to: 0,
item: c
});
c.linkedItems.push({
from: 0,
to: 0,
item: a
}, {
from: 0,
to: 0,
item: b
});
var obj = {
things: {},
otherThings: {},
items: [a, b, c]
};
From obj, I need to replace each references in the "linkedItems" attribute, by their id. I tough the easier way was to stringify it first ... :)