javascript - convert an object to array with property names too -
i have object like:
obj { property1: "8898" property2: "2015-04-27 08:03:39.041" property3: "27" property4: "c10" }
i need convert array.
my code:
var results=[]; (var property in obj) { if (obj.hasownproperty(property)) { results.push(obj[property]) } }
here getting values. need have following result ["property1":1,"property2":2]
instead of [1,2]
i tried append property name did not have desired result.
var obj = { property1: "8898", property2: "2015-04-27 08:03:39.041", property3: "27", property4: "c10", }; var results = []; (var property in obj) { if (obj.hasownproperty(property)) { var str = property +':'+ obj[property]; results.push(str) } } alert(results);
Comments
Post a Comment