Renat Gatin Renat Gatin - 3 months ago 9
AngularJS Question

How to get Array from Array String in JavaScript or AngularJS?

Initially I have variable that contains string data

var stringArray = "[{'middleName':'T','lastName':'TEST5LAST','occupation':'QA','homeAddressZipcode':'85001','entitySequenceNumber':7,'homeAddressCity':'PHOENIX','ssn':'111111115','cellPhone':'4807363273','employer':'ABC','workPhoneExtension':'5555','entityType':'JOINT','homePhone':'4807363272','identificationType':'0','email':'FIRST5.LAST5@TEST.COM','workPhone':'4807363274','firstName':'TEST5FIRST','homeAddressStreet':'8000','homeAddressState':'AZ'}]";


Is there a function in JavaScript or AngularJS that will allow me to build a real JavaScript Array like this?:

var realArray = [
{
"middleName":"T",
"lastName":"TEST1LAST",
"occupation":"HR",
...
},
{
"middleName":"T",
"lastName":"TEST5LAST",
"occupation":"QA",
...
},
...
];

Answer

Try this.

realArray = JSON.parse(stringArray);
Comments