列表的迭代
迭代数组Array对象
var data = ["dog", "pig", "cat"];// 1、遍历下标索引for (let index in data) { console.log(index + "->" + data[index]);}/** 0->dog 1->pig 2->cat */// 2、遍历值for (let value of data) { console.log(value);}/** dog pig cat */对象的迭代
var data = { name: "Tom", age: 23};// 1、遍历keyfor(let key in data){ console.log(key);}/** name age */// 2、遍历对象键值对for(let [key, value] of Object.entries(data)){ console.log(key + "->" + value);}/** name->Tom age->23 */// 3、遍历对象键for(let key of Object.keys(data)){ console.log(key);}/** name age */// 4、遍历对象值for(let value of Object.values(data)){ console.log(value);}/** Tom 23 */