es6中 for…of 循环遍历数组对象

//数组对象  
const myArray = [{
      id: 1,
      name: "李特成",
      age: '20',
      gender: '男',
      arr: ['湖南长沙', 'IT技术']
    },
    {
      id: 2,
      name: "范冰冰",
      age: '15',
      gender: '女',
      arr: []
    },
    {
      id: 3,
      name: "范斌",
      age: '60',
      gender: '男',
      arr: ['湖南衡阳', '测试']
    },
    {
      id: 4,
      name: "凡冰",
      age: '70',
      gender: '男',
      arr: ['湖南永州', 'C#']
    },
  ]

  //通过for…of 循环
  html = "";
  html += "
    "; for (let v of myArray) { //console.log(v); html += "
  • 名称:" + v.name + "地址/技术:"; if (v.arr.length != 0) { let subArr = v.arr; for (let s of subArr) { //console.log(s); html += "" + s + "/"; } } html += "
  • "; } html += "
"; $("body").append(html);
es6中 for…of 循环遍历数组对象_第1张图片

你可能感兴趣的:(ECMAScript,6)