DEV Community

Cover image for Five powerful JavaScript array methods.

Five powerful JavaScript array methods.

Taslan Graham on June 08, 2020

Full article can be found here. Arrays are very common data structures in programming and is supported by many modern programming languages. In ge...
Collapse
 
itsjzt profile image
Saurabh Sharma
Array(10).fill(null).map(_, i => i)
Enter fullscreen mode Exit fullscreen mode

This creates an array of the given range 10 in this case. I use this all the time

Collapse
 
1987cr profile image
Carlos Riera

Shorter alternative :)

[...Array(10).keys()]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
itsjzt profile image
Saurabh Sharma

Oh nice,

Collapse
 
taslangraham profile image
Taslan Graham

Wow!
I've never used this before. Will give it a try soon.

Collapse
 
octocodeio profile image
Wojciech Dasiukiewicz

For me, one of the top useful functions from Array object is Array.from(). You can transform for example NodeList to regular Array of Objects

Collapse
 
jamesthomson profile image
James Thomson

You can transform for example NodeList to regular Array of Objects

You can also do this using the ES6 spread operator, e.g. const arr = [...document.querySelectorAll('div')];

Collapse
 
_merksam profile image
Evgeniy Viniychuk

I guess we also shouldn't forget about some and every methods, they give you a great possibility to check complex conditions and are useful sometimes.

Collapse
 
mugas profile image
Ricardo Moreira

Good post Taslan

Collapse
 
taslangraham profile image
Taslan Graham

Glad that you liked it, Ricardo

Collapse
 
naveenkumar337 profile image
naveenkumar337

This is great article, to explain mostly used Array methods

Collapse
 
taslangraham profile image
Taslan Graham

Glad that you found it useful!

Collapse
 
anselmegildas profile image
AnselmeGildas

Salut avec quoi (quelle application) vous réalisez les créas pour présenter les bouts de code.