3 Useful JavaScript Array Methods

Objective

In todays blog we will discover some useful JavaScript Array Methods.

concat()

Concatenates two arrays:

const arr1 = ["Hi", "Everyone"];
const arr2 = ["I", "am", "Asim"];
const children = arr1.concat(arr2); // ["Hi", "Everyone", "I", "am", "Asim"]

every()

Checks if every element in an array pass a test

const ages = [32, 33, 16, 40];

ages.every(checkAge)

function checkAge(age) {
  return age > 18;
}

filter()

Creates a new array with every element in an array that pass a test

const nums = [-1, 6, 8, -7];
const result = nums.filter(checkPositive);

function checkPositive(num) {
  return num > 0;
}