Home>Article>Web Front-end> How to convert array to json format in javascript
In javascript, you can use the conversion function "JSON.stringify()" to convert the array into json format. The syntax format is "JSON.stringify(array)"; this function can convert arrays or objects. Then return a string containing the JSON text.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript array to JSON format
Point 1: Conversion function JSON.stringify()
Point 2: When writing an array in js var data = new Array() But if you want to convert to json for display, you must write var data = {}, otherwise the converted json will be empty.
First look at an incorrect format:
Effect:
## Correct format: Result:Programming Video! !
The above is the detailed content of How to convert array to json format in javascript. For more information, please follow other related articles on the PHP Chinese website!