1//create an array like so:
2var colors = ["red","blue","green"];
3
4//you can loop through an array like this:
5for (var i = 0; i < colors.length; i++) {
6 console.log(colors[i]);
7}
1console.log(Array.from('foo'));
2// expected output: Array ["f", "o", "o"]
3
4console.log(Array.from([1, 2, 3], x => x + x));
5// expected output: Array [2, 4, 6]
6
1//Array.from() lets you create Arrays from array-like objects
2//(objects with a length property and indexed elements);
3//and also:
4
5//More clearly, Array.from(obj, mapFn, thisArg)
6//has the same result as Array.from(obj).map(mapFn, thisArg),
7//except that it does not create an intermediate array.
8//Basically, it's a declaration that overrides the length property of the method
9//(so that it has to be used with the same name length),
10//setting it with the same value of the given variable.
11//The values are still undefined, it's just a different notation. Take a look:
12
13console.log(Array.from(length, (_,i) => i));
14// It doesn't works with non-iterables
15// In this case we are passing an integer
16
17console.log(Array.from({LENGTH}, (_,i) => i));
18// It doesn't work with a property name different from "length"
19
20console.log(Array.from({length}, (_,i) => i));
21// It works because overrides the .length property of the array
22// The method Array.from() assumes that the property...
23// ...is referring to an iterable (also if not declared)
24
25console.log(Array.from(Array(length), (_,i) => i));
26// This is the demonstration of the above assertion
27// In this case we are using a declared array through...
28// ...an instance of the straight method Array()...
29// ...that accepts an integer as value
30
31//in case any one reads this a got this from er0s in edabit