6. 数组练习

(1) 打印对象⾥数组的⻓度

  1. console.log(result.list.length)

(2) 打印最后数组最后⼀个成员的所有属性值

  1. var len = result.list.length;
  2. var item = result.list(len-1);
  3. 最后一个数组的所有对象:console.log(item.categoryId);
  4. console.log(item.name);
  5. console.log(item.iconUrl);

var result = {
“code”: 666,
“msg”: “success”,
“list”: [{
“categoryId”: 145,
“name”: “时令鲜果”,
“iconUrl”: “/img/fresh/other/r1.png”
}, {
“categoryId”: 243,
“name”: “海鲜⽔产”,
“iconUrl”: “/img/fresh/other/r2.png”
}, {
“categoryId”: 279,
“name”: “家禽蛋”,
“iconUrl”: “/img/fresh/other/r3.png”
}, {
“categoryId”: 346,
“name”: “地⽅农产”,
“iconUrl”: “/img/fresh/other/r4.png”
}, {
“categoryId”: 436,
“name”: “百果园公司”,
“iconUrl”: “/img/fresh/other/r5.png”
}, {
“categoryId”: 357,
“name”: “农品茗茶”,
“iconUrl”: “/img/fresh/other/r6.png”
}, {
“categoryId”: 6,
“name”: “五⾕杂粮”,
“iconUrl”: “/img/fresh/other/r7.png”
}, {
“categoryId”: 311,
“name”: “⽜⽺⾁”,
“iconUrl”: “/img/fresh/other/r8.png”
}]
}

  1. 1. 数据类型有哪⼏种(提问)
  2. 问题一回答:
  3. 1string字符串 2boolean布尔值 3object对象(数组函数) 4null 对象的一种特殊类型
  4. 5undifined 6number数字类型
  1. 2. 什么时候数据类型会是 undefined?
  2. 问题儿回答
  3. 1:声明了变量但未设置初始值(赋值)
  1. 3. 字符串有哪⼏种形式,⼀般⽤那种?
  2. 问题三回答
  3. “” '' ``(模板字符串)
  4. 推荐用单引号
  1. 4. 常⻅的数字有哪些?
  2. 问题四回答
  3. 整数⼩数最⼤值和最⼩值
  1. 5. var obj = {name: '王菲', age: 40} ,⽤两种⽅式在控制台打印属性值 name 的值
  2. 用.点出来 也可以用中括号加单引号['']