lundi 20 février 2017

What's the need of iterator in JavaScript arrays?

Recently I became aware of ES6 iterator went to the help of JS arrays. I searched about it but still confused about its philosophy of design, because other methods was still OK.

On the other hand I've been told not to use it!

var arr = ['w', 'y', 'k', 'o', 'p'];
var eArr = arr[Symbol.iterator]();

// your browser must support for..of loop
// and let-scoped variables in for loops

for (let letter of eArr) {
  console.log(letter);
}

Was it just because of for..of support?

Of course, this feature hasn't been added to JS objects.

Aucun commentaire:

Enregistrer un commentaire