Javascript Array.from(), fullfilling that Empty Jar

Would you like to create an iterable object just by knowing the limit? if yes, this blog is for you.

SO , i am not gonna use more words and directly jump into the problem and how this helped me to solve it.

Problem — To render multiple dom nodes on the basis of a count variable where the count is a number variable.

Solution — Well you can loop through with count number of times and generate that many nodes.

for(var i=0;i<count;i++){
document.write('Item: ' + (i+1) + ' of ' + count+ '<br/>');
}

well there is nothing wrong with this solution , this will work perfectly fine. But personally i don’t like the for word in my code much and if i avoid it as much as possible.

Array.from() for rescue :)

Array.from will create an array like object for iteration.So how does it solve the problem.

well i have to say in one line.

Array.from({length:20},(v,i)=> {return i});

If you wanna look more deeper into the method mozilla doc is best place for you.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.