Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  168] [ 3]  / answers: 1 / hits: 18180  / 14 Years ago, mon, april 26, 2010, 12:00:00

I'm retrieving an array of objects from a hidden html input field. The string I'm getting is:



{id:1234,name:john smith,email:[email protected]},{id:4431,name:marry doe,email:[email protected]}


Now I need to pass this as an array of objects again. How do I convert this string into array of objects?


More From » arrays

 Answers
31
var array_of_objects = eval([ + my_string + ]);


This executes the string as code, which is why we need to add the [] to make it an object. This is also one of the few legitimate uses for eval as its the fastest and easiest way. :D


[#96974] Thursday, April 22, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elaine

Total Points: 628
Total Questions: 111
Total Answers: 104

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
;