Javascript Practice Day 4 : Iterators,Iterables ,Generators
Iterable object will have a Symbol.iterator proto .Sets,Weak Set,Maps, Weak Maps are newly introduced Javascript Iterable datatypes ."for of" is a new for loop that can be used with the itrable datatypes .Set do not store duplicate values. reference Site -https://www.youtube.com/watch?v=TJpkYvSREtM let mySet = new Set([1,2,2,3,4]) console.dir(mySet); for (let v of mySet){ console.log(v); } //Use of Symbol.iterator traverse through elements let myArray=[1,2,3,4]; let iterator= myArray[Symbol.iterator](); console.log(iterator.next()); //output {value: 1 and done :false } (value is the element present in the index and done :false,the array is not yet completed console.log(iterator.next()); console.log(iterator.next()); console.log(iterator.next()); console.log(iterator.next()); let NumArray=[1,2,3,4]; console.dir(NumArray); //non iterable object will not have a Symbol.iterator proto let anyOtherObject={ name: "John", ...
Comments
Post a Comment