From and Of in Arrays - Let's Learn ECMAScript 2021 with Earl Duque
In this episode, we're going to be talking
about some new functionality for arrays. Specifically we're going to be talking
about from and of So for from to show you how it works, so if I have a string and it says incident001 and I have another variable
called incidentArray, I can take that string and use array from to take that string and basically
spread it out across an array. So I'm going to go ahead
and create a log statement saying, take that incident array and join it with some space and commas. there you go and it spread it out across the array. in a similar fashion, if I have a set, I can actually create an array
from that set. So here's a new
set with unique values in it. And then I have array dot from that. So and if I print this out,
you'll see that it created an array
from that existing set. The array of method
inside the arrays works like this. So if I have numbers, I can say array of 1 to 3. And what happens with that It creates an array out of those elements. This also works for other data types
like strings. It's just another straightforward way
of creating arrays from lists of values. That's all. It's available to
you. Use it if you want to.
https://www.youtube.com/watch?v=Gp79udl5zKw