简体   繁体   中英

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",
     ...
  },
  ...
];

尝试这个。

realArray = JSON.parse(stringArray);

JSON.parse(stringArray)返回JSON对象

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM