The problem is as follows: a simple application of a single object has been completed, hoping to define an array that can contain multiple students.
The code copy is as follows: var student = new Object();
student.name = "Lanny";
student.age = "25";
student.location = "China";
var json = JSON.stringify(student);
Method 1:
The code copy is as follows: var students = [];
students[students.length] = new Object();
students[students.length].name = "Lanny";
students[students.length].age = "25";
students[students.length].location = "China";
var json = JSON.stringify(students);
Method 2:
The code copy is as follows: var student = new Object();
student.name = "Lanny";
student.age = "25";
student.location = "China";
students = (students || []).push(student);
var json = JSON.stringify(students);
To view more JavaScript syntax, you can follow: "JavaScript Reference Tutorial" and "JavaScript Code Style Guide". I also hope that everyone will support Wulin.com more.