JavaScript — 3 Things you should know

Arrays Edition

Vincent Collis
3 min readFeb 12, 2021

JavaScript may very well be the most popular programming language in use today. JavaScript’s ability to create web applications, front-end, back-end, and mobile applications with React Native makes it a dominant gene in the genetic pool of programming languages. With that said, we must understand the basics of the language to create web applications masterfully. In the article, I’m going to share with you three things you should know about Arrays to be on the way to mastering JavaScript.

Merge arrays

There are two easy ways to go about mergeing arrays. The first is using JavaScripts built in method concat().

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

The more advanced way you will see, especially when managing State in React using libraries like Redux, is utilizing the spread operator (…).

There is a simple way to merge any amount of arrays into one in one line of code.

Converting Arrays → Objects

Another great use of the spread operator (…) is to convert Arrays into Objects. Let’s say we need to change our dog array into an object. The fastest way would be to call the dogs array with (…) in front of it within brackets {}.

Combine / Sum values of an array

There will be times you come across problems where you must combine or sum all the array values. Depending on the size of that array, using a for loop may be taxing on your application. Hence a more efficient technique must be applied. In comes .reduce()

.reduce() allows you to manipulate an array based on the conditions set in the call back function. Here x is the returned value while y is the next element in the method’s array. In the future, I will write a post about reduce and link it here!

--

--