javascript如何定义对象数组
问题如下,已经完成单个对象的简单应用,希望定义一个数组,能包含多个student。
代码如下:
var student = new Object(); student.name = "Lanny"; student.age = "25"; student.location = "China"; var json = JSON.stringify(student);
方法一:
代码如下:
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);
方法二:
代码如下:
var student = new Object(); student.name = "Lanny"; student.age = "25"; student.location = "China"; students = (students || []).push(student); var json = JSON.stringify(students);
查看更多JavaScript的语法,大家可以关注:《JavaScript 参考教程》、《JavaScript代码风格指南》,也希望大家多多支持安科网。
相关推荐
breakpoints 2020-05-17
zrtlin 2020-11-09
xuebingnan 2020-11-05
wikiwater 2020-10-27
heheeheh 2020-10-19
Crazyshark 2020-09-15
softwear 2020-08-21
ZGCdemo 2020-08-16
jczwilliam 2020-08-16
littleFatty 2020-08-16
idning 2020-08-03
jinxiutong 2020-07-26
lanzhusiyu 2020-07-19
Skyline 2020-07-04
xiaofanguan 2020-06-25
Aveiox 2020-06-23