For some reasons, i need a function to convert an object inside an array with null property to an object with empty object property.
The function should be recursive, and must work for any object (deep nested, array in array, array in object, etc...)
There is an example of what i need :
var obj = {
"parent" : [
null,
{"child" : 2},
{"child" : 3}
],
"parent2" : {
"parent3" : [
{"child" : 1},
null,
{"child" : 3}
]
},
"parent4" : [
{"child" : [
{"childa" : 1},
{"childa" : 2},
null
]
},
{"child" : [
{"childa" : 1},
null,
null
]
},
null
]
}
Then :
var obj2 = nullToEmptyObject(obj);
And obj2 should look like this :
{
"parent" : [
{},
{"child" : 2},
{"child" : 3}
],
"parent2" : {
"parent3" : [
{"child" : 1},
{},
{"child" : 3}
]
},
"parent4" : [
{"child" : [
{"childa" : 1},
{"childa" : 2},
{}
]
},
{"child" : [
{"childa" : 1},
{},
{}
]
},
{}
]
}
I didn't do anytry yet, because i don't know how to recursive. If you can give me a starting code, i could complete.
Thanks guy, edit me if my english is bad !