想分别打印出 bill, steve, bann 的各项
var friends={
bill:{firstName:'Bill',lastName:'Manson',number:'123',address:['Hanson225, Sanhen St.','LA','903987']},
steve:{firstName:'Steve',lastName:'Nanon',number:'456',address:['JackMarry59, Nahop St.','CA','809756']},
bann:{firstName:'Bann',lastName:'Mason',number:'789',address:['Homon25, Hogon St.','OH','309878']}
};
var list=function(friends){
for(var i=0;i
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
为什么要用for循环而不去用for……in呢?对象可以通过对象[0]对象[1]的形式获取到对应的属性值吗?这个求问,好像我是没有这么拿过。只有在for…in里这么用过。
friends[i][j]作为console.log的参数,后面不该加引号报错是这里多了个分号console.log(friendsi
;);普通对象用for...in循环
普通数组不能用序号索引吧,只能用关键字索引来返回对应的值。试了下for in 可以