0

When I try to get the index in a for-of loop, it gives me the error:

VM343:60 Uncaught TypeError: undefined is not a function at window.onload (VM343:60)

const items = [
  {
    id: 1,
    name: 'asdffd'
  },
  {
    id: 2,
    name: 'asd3'
  },
  {
    id: 3,
    name: 'asdfsfsfdffd'
  }
];

for (let [index,item] of items) {
  console.log(item.name);
}

jsfiddle: http://jsfiddle.net/edwardtanguay/ob4t7ee9/

What syntax do I need to get the index for each iteration?

Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047

0 Answers0