DEV Community

Cover image for JavaScript Array methods

JavaScript Array methods

Shreyas Pahune on June 13, 2021

We have a lot of array methods in JavaScript but in this blog you are gonna see only the most useful methods and after reading this, I am pretty su...
Collapse
 
jimhol profile image
jimhol

indexOf is good when you need the index. If you just want to know whether the value is in the array or not, you then have to test the result against -1. Alternatively you could use .includes() to get true or false directly.

Collapse
 
shreyazz profile image
Shreyas Pahune

Yup that’s correct! But indexOf tells you precisely where the value is found…✅

Collapse
 
_genjudev profile image
Larson

Just a reminder that arrow functions are not just another syntax. An alternative expression with limited use.

developer.mozilla.org/en-US/docs/W...

Collapse
 
mardiya profile image
Mardiya Zubairu

Thanks for this post. I just finally understood reduce method😊

Collapse
 
shreyazz profile image
Shreyas Pahune

Awesome 😇

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
shreyazz profile image
Shreyas Pahune

Thanks bro!

Collapse
 
rlancer profile image
Robert Lancer

sort() also makes a new array and the original array is un-touched

That's not true, sort modifies the array in place

Collapse
 
someshium profile image
someshium

Also, how to make these code snippets images?

Collapse
 
shreyazz profile image
Shreyas Pahune

Copy and Paste your code in this website : carbon.now.sh/

Collapse
 
deniskatsapov profile image
deniskatsapov

Thanks 👍 .
I am still confused about the methods .

Collapse
 
shreyazz profile image
Shreyas Pahune • Edited

confused about methods discussed in this blog?? or the term method?

Collapse
 
someshium profile image
someshium

I am not getting how the sort function adds the elements to a new array based on return value 1 or -1. Can you please explain this?

Collapse
 
shreyazz profile image
Shreyas Pahune

That is how the sort function is made...you just have to give it a variable, and if the values matches then it will get pushed into the new variable we created.

Collapse
 
tahavepari profile image
Tahavepari

It's very helpful to me Keep it up bro 🔥

Collapse
 
shreyazz profile image
Shreyas Pahune

Thanks bro