Renat Gatin
Renat Gatin

Reputation: 6394

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':'[email protected]','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",
     ...
  },
  ...
];

Upvotes: 0

Views: 68

Answers (2)

Prashant Gurav
Prashant Gurav

Reputation: 503

JSON.parse(stringArray) return JSON object

Upvotes: 0

patrickcipot
patrickcipot

Reputation: 307

Try this.

realArray = JSON.parse(stringArray);

Upvotes: 1

Related Questions