Home > Article > Web Front-end > How to convert json data to array in javascript
In javascript, you can use the "JSON.parse()" method to convert json data into an array. This method can convert a JSON string into a JavaScript value or object. The syntax "JSON.parse(json data)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JSON is a format used to store and transmit data. JSON is usually used by the server to transfer data to web pages.
The JSON format is syntactically identical to the code that creates JavaScript objects. Because they are similar, JavaScript programs can easily convert JSON data into JavaScript objects.
javascript json data to array
//json字符串转数组 var jsonStr = '[1,2,3,{"a":1}]'; var jsarr=JSON.parse( jsonStr ); console.log(jsarr); console.log(jsarr[0]);
Description:
JSON.parse() method is used Convert a JSON string to a JavaScript value or object. Syntax format:
JSON.parse(text[,reviver])
Parameter description:
text: required, a valid JSON string.
reviver: Optional, a function that converts the result. This function will be called for each member of the object.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to convert json data to array in javascript. For more information, please follow other related articles on the PHP Chinese website!