i have use generate javascript multiple object based page result, convert json string. json.stringify
not display properly. don't know why display this. have added example of coding
var sample_object = []; var sub_array = []; sub_array["type"] = 'i'; sample_object.push(sub_array); console.log(sample_object); console.log(json.stringify(sample_object));
result :-
[array[0]] 0: array[0] length: 0 type: "i"_ _proto__: array[0] length: 1__proto__: array[0]
json.stringify output
[[]]
thanks in advance!
it's because can't have named arguments in array. need change sub_array
object. note variable have named sample_object
array. here's working version appropriately named variables:
var sample_array = []; var sub_object = {}; sub_object["type"] = 'i'; sample_array.push(sub_object); console.log(sample_array); console.log(json.stringify(sample_array)); // = '[{"type":"i"}]'
you can shorten first 4 lines this:
var sample_array = [{ type: 'i' }];
Comments
Post a Comment