Author - StudySection Post Views - 141 views
javascript

5 JavaScript Array Methods You Should Know

Introduction

JavaScript has become popular language and its popularity is increasing day by day. Almost every website uses JavaScript directly or indirectly. There are many popular frameworks built in it like React, Angular, Vue, etc.

Here are the 5 JavaScript array methods you should know:

  1. forEach:
    This can help you to iterate the array’s values.
    Const array = [0, 1, 2, 3];
    array.forEach((item) => {
    console.log(item);
    });
  2. Reduce:
    The reduce() method applies a function against an accumulator and each element in the array to reduce it to a single value
    Const array = [0, 1, 2, 3];
    Const sum = array.reduce((total, value) => total + value);
    console.log(sum); // output: 6
  3. Filter:
    This method creates a new array according to the passed condition inside the provided function.
    Const array = [0, 1, 2, 3];
    Const filtered = array.filter(num => num>2);
    console.log(filtered); // output: [3]
  4. Map:
    This method builds new array by calling the provided function in each element.
    Const array = [0, 1, 2, 3];
    Const newArray = array.map(num => num +1);
    console.log(newArray); // output: [0, 1, 2, 3];
  5. Includes:
    This method checks if array consists of the item passed in the method.
    Const array = [0, 1, 2, 3];
    array.includes(0); // output: true
    array.includes(5); // output: false

If you have skills in PHP programming and you want to enhance your career in this field, a PHP certification from StudySection can help you reach your desired goals. Both beginner level and expert level PHP Certification Exams are offered by StudySection along with other programming certification exams.

Leave a Reply

Your email address will not be published.