Input:
{ key : "value" ,
list : [
{
key : "values1" ,
list : [
{ key : "value2" , list :[{ key : "simpleValue" } ]
}
]
},
{
key : "value3"
}
]
}
Output:
{key : ["value" , "values1" , "values2" , "simpleeValue", "values3"]}
the code that I wrote for conversion is
var outputArray=new Array();
var count=0;
function recursion(testData){
if(testData.key==undefined)
{
return ;
}
else
{
outputArray[count]=testData.key;
count++;
for(var k in testData.list)
{
testData1=testData.list[k];
recursion(testData1);
recursion(testData.key);
}
}
return outputArray;
}
The output will only give me the value list an array,like [ 'value', 'values1', 'value2', 'simpleValue', 'value3' ], how do I use the hash method to get the correct output?