ES6 and Typescript Tutorial - 39 - Iterating Objects

preview_player
Показать описание

📱 Follow Codevolution

ES6 | ES2015 | Typescript | ES6 Tutorial | ES2015 Tutorial | Typescript Tutorial | ES6 Tutorial for Beginners | ES2015 Tutorial for Beginners | Typescript tutorial for Beginners
Рекомендации по теме
Комментарии
Автор

you can also use for (let p of and it will work

omobrain
Автор

This iterator thing isn't really working for me the way you described. But a working method is already enclosed:
for (property of Object.keys(obj)){
console.log(`${property} -> ${obj[property]}`);
}

nicolaiveliki
Автор

thank you so much
but why did you not use in this video the same idea of the previous video...
person[Symbol.iterator] = function() {
let that = this;
let properties = Object.keys(person);
let count = 0;
return {
next: function() {
return count < properties.length ? {value: that[properties[count++]], done: false} : {value: undefined, done: true};
}
}
}

osamatalaat
Автор

What does the whole iteration logic have to do with Symbols in the first place? Symbols are a new data type which has unique id per element and Symbol.iterator returns the default iteration logic for iterable collections else we create a custom logic and apply that, for example to an object which is not iterable in the first place, to get the iterated list just like what was explained in the video.
I think I got that part but my question still lies at the part why Symbol.iterator? why not just have a key called iterator with iteration logic?

KalyanSreeramula
Автор

how can we use this with classes in Angular?

architgoel
Автор

When I run this code, chrome hangs. In console I see lakhs of undefined message[ 444539 undefined]. subsequently my system hangs.

prince
Автор

it looks like now this code is not workable

alphabetta