Iterate over JavaScript object with index

Viewed 52637

I am trying to loop over a JavaScript object in ES6.

 for (let [value, index] of object) {
    do something with rest
    if (index >= 1) {
       // do something with first item
    }
  }

It works fine, although when I try to use index to get the first item it returns an error in console:

Uncaught TypeError: Invalid attempt to destructure non-iterable instance

Any ideas on how to loop over an object with index? thanks

2 Answers
Related