7 JavaScript ES6 Array Functions You must Know

2021-11-17

Coding in the dark

Javascript latest versions provide us with many cool functions to build logic faster! So, today we're going to talk about 7 JavaScript array functions, for more code efficiency and less code complexity. Let's get started!

Introduction

Hello friends,

Javascript latest versions provide us with many cool functions to build logic faster! So, today we're going to talk about 7 JavaScript array functions, for more code efficiency and less code complexity. Let's get started!

Concat()

As the name says. This method returns a new array object which contains two or more merged arrays.

concat firstArray coding

Map()

This function is magical, you'll definitely use it. This method creates a new array populated with the results of calling a provided function on every element in the calling array.

Map coding const firstArray

Filter()

Very handy function, you'll use it more than often. This method creates a new array with all elements that pass the test implemented by the provided function.

constnumbers coding filter

IndexOf()

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

coding indexOf

Reduce()

The reduce() method executes a user-supplied “reducer” callback function on each element of the array, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

coding Reduce

Slice()

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.

coding slice

Splice()

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.

Splice coding

Conclusion

That's it for today's blog post. Make sure to use these array functions and reduce your code complexity! Any questions or suggestions? Get in touch by email or Instagram DMs.

Enjoyed this article? Consider sharing it.