0

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

2 Answers 2

1

Try this.

realArray = JSON.parse(stringArray);
Sign up to request clarification or add additional context in comments.

Comments

0

JSON.parse(stringArray) return JSON object

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.