DEV Community

cisneros-a
cisneros-a

Posted on

Different Array Methods (cont.)

Here are a few more array methods that will useful as you learn javascript!

Array.concat()

Alt Text

What it does:

The concat method will create a new array by adding the values from the array that was passed in as an argument(numsToo) to the end of the original array.

What it returns:

This returns a brand new array. The two array that were combined remain the same. You'll see at the bottom, that nums returns its original values.

Array.indexOf()

Alt Text

What it does:

The indexOf will take an argument (string, integer, etc) and find the first instance of that in the array.

What it returns:

This will return the index of the first instance of the value that was found. In this instance, we are looking for the number 3 and it is first found at the 2nd index.

Array.reverse()

Alt Text

What it does:

The reverse method will take an array and reverse it.

What it returns:

Not only will this return a return the array reversed, but the array will be modified and reversed. You can see at the bottom when we call nums again, it is still reversed.

Array.join()

Alt Text

What it does:

The join method will do basically what it says. It will join the indexes in the array with what is passed in as an argument. By default it will join the items by a comma.

What it returns:

This will return a string of the joined array. Keep in mind that the join method will not modify the original array.

Top comments (0)