Is it possible to remove the circular type that is inside an object?
let say
result = {
a : [Array],
b : [Object],
c : [Circular],
d : 'string'
e : {
x : [Circular],
y : {
z : [Circular]
}
}
}
to
result = {
a : [Array],
b : [Object],
d : 'string'
}
I wanted to filter out all the circular type within the objects.
Attempt 1:
Since the name for each object is also the same in the children object. I tried to delete it since most children circular object only points to the parents. (actually, I got confused on this part). Here is the code i tried to use.
let keys = Object.keys(obj)
keys.forEach(val => {
if (obj[val] instanceof Object || obj[val] instanceof Array) {
Object.values(obj[val]).filter(function (value, index, arr) {
if (keys.indexOf(Object.keys(value)[index]) > 0) {
delete obj[val][index]
}
})
}
})