Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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",
     ...
  },
  ...
];
share|improve this question
3  
Your sample string has a closing ] but no opening [, btw. – S McCrohan Aug 3 at 18:07
1  
native function in AngularJS would be angular.fromJson(stringArray); – mzmm56 Aug 3 at 18:07
    
Yes, S McCrohan, you are right. It was my typo. Corrected it. – Renat Gatin Aug 3 at 18:09
    
Your Array contains only one element. Do you confirm ? – kevin ternet Aug 3 at 18:29
    
In current example yes, but it should handle multiple elements.. – Renat Gatin Aug 3 at 19:06
up vote 1 down vote accepted

Try this.

realArray = JSON.parse(stringArray);
share|improve this answer

JSON.parse(stringArray) return JSON object

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.