<script>// var perosn = {name: "张三", age: 16, gender: true};// var name = perosn["name"];// alert(name)
var persons ={
persons:[{name:"张三",age:18,gender:true},{name:"李四",age:19,gender:false},{name:"王五",age:20,gender:true},]}alert(persons.persons[1]["name"])alert(persons.persons[2].name)</script></head>
二、遍历
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title><script>//1.定义基本格式
var person ={"name":"张三", age:23,'gender':true};
var ps =[{"name":"张三","age":23,"gender":true},{"name":"李四","age":24,"gender":true},{"name":"王五","age":25,"gender":false}];//获取person对象中所有的键和值//for in 循环/* for(var key in person){
alert(key+":"+person[key]);
}*///获取ps中的所有值for(var i =0; i < ps.length; i++){
var p = ps[i];for(var key in p){alert(key+":"+p[key]);}}</script></head><body></body></html>