Reputation: 2230
I am trying to store the values inside a javascript object notation based on the field selected by user. I was able to store the value in to a string separated with commas, Bt if the term Im trying to find is an array, I get [object object] in return, as it is an array. I want to know how I can store all the items in that array in to a variable separated by commas, here for example if I select "Time", then it should return Dec 9, 1, 2012
In the example, there is a function findProps, If I give the argument, entityCount inside findProps("entityCount", data), I will get a proper return type as 50, bsed on the json Ive provided. Bt If I add, findProps("Time", data);, since it is an array, it returns [object, object], not the values inside those arrays and I want the all values inside that array to be displayed(like Dec 9, 1, 2012
) and the keys inside each array could be different and the depth of array could also be different. Im just using a static example here.
The part Ive reached returns the value if its a non array, http://jsbin.com/obehog/3/edit
There is another example which I came close to doing, http://jsbin.com/obehog/4/edit bt Im bad at recursion so Im stuck at this..
and the depth of the arrays could change, it wont be the same in each case. so going through loop will not work..
Upvotes: 0
Views: 204
Reputation: 340
if i've been understanding your desire, than you want to "seralize" an object (containing strings, arrays and other objects) into a string. therefor you just need to iterate through your object and seralize the parts of it.
quick, dirty and recursive: http://jsfiddle.net/AwhfV/1/
just alter it for your needs
Upvotes: 0
Reputation: 146
If I understand you right, you code needs additional function, which will write all object's properties to array. Look at my solution: http://jsbin.com/obehog/6/edit#source
Upvotes: 1