decode now
  • Home
  • Blog
    • AI
    • Backend
      • Java
    • Career & Interviews
    • Frontend
      • HTML
      • CSS
      • JavaScript
    • Full Stack
  • Notes
  • About us
  • Contact US
No Result
View All Result
AI News
  • Home
  • Blog
    • AI
    • Backend
      • Java
    • Career & Interviews
    • Frontend
      • HTML
      • CSS
      • JavaScript
    • Full Stack
  • Notes
  • About us
  • Contact US
No Result
View All Result
Decode Now
No Result
View All Result
JavaScript Array Methods

Introducing JavaScript Array Methods

admin by admin
June 7, 2026
in JavaScript
0
585
SHARES
3.2k
VIEWS
Summarize with ChatGPTShare to Facebook

Last Updated on June 7, 2026 by admin

Array Methods in JavaScript

Array Methods in JavaScript are some built-in methods and properties that simplify operating on Arrays. In JavaScript, arrays are a fundamental data structure that allows you to store multiple elements under a single variable name. There are several built-in methods and properties that simplify operating on arrays.

 

Here are some of the most common array methods in JavaScript:


1. push()
:

The push() method adds one or more elements to the end of an array and returns the new length of the array.
let array = [1, 2, 3];
array.push(4);
// array is now [1, 2, 3, 4]

2. splice():

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
let array = [1, 2, 3, 4, 5];
array.splice(2, 1); // Removes 1 element at index 2
// array is now [1, 2, 4, 5]

3. 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.
let array1 = [1, 2];
let array2 = [3, 4];
let newArray = array1.concat(array2);
// newArray is [1, 2, 3, 4]

4. forEach():

The forEach() method executes a provided function once for each array element.
let array = [1, 2, 3];
array.forEach(function(element) {
console.log(element);
});
// Output: 1 2 3

5. map():

The map() method creates a new array with the results of calling a provided function on every element in the calling array.
let array = [1, 2, 3];
let doubledArray = array.map(function(element) {
return element * 2;
});
// doubledArray is [2, 4, 6]

6. filter():

The filter() method creates a new array with all elements that pass the test implemented by the provided function.
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// Example 1: Filtering even numbers
let evenNumbers = numbers.filter(function(number) {
return number % 2 === 0;
});
// evenNumbers is [2, 4, 6, 8, 10]
// Example 2: Filtering numbers greater than 5
let greaterThanFive = numbers.filter(function(number) {
return number > 5;
});
// greaterThanFive is [6, 7, 8, 9, 10]

JAVASCRIPT ARRAY METHODS
CODING

7. find():

The find() method returns the first element in the array that satisfies the provided testing function.
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// Find the first even number
let firstEvenNumber = numbers.find(number => number % 2 === 0);
// firstEvenNumber is 2
// Find the first number greater than 5
let firstGreaterThanFive = numbers.find(number => number > 5);
// firstGreaterThanFive is 6

8. sort():

The sort() method sorts the elements of an array in place and returns the sorted array.
let numbers = [4, 2, 5, 1, 3];
numbers.sort(); // Sorts the array as strings: [1, 2, 3, 4, 5]
// To sort numbers numerically
numbers.sort((a, b) => a – b); // Sorts the array numerically: [1, 2, 3, 4, 5]

9. 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.
let fruits = [‘apple’, ‘banana’, ‘orange’, ‘pear’];
let indexBanana = fruits.indexOf(‘banana’);
// indexBanana is 1
let indexGrape = fruits.indexOf(‘grape’);
// indexGrape is -1, as ‘grape’ is not in the array

10. includes():

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
let fruits = [‘apple’, ‘banana’, ‘orange’, ‘pear’];
let hasBanana = fruits.includes(‘banana’);
// hasBanana is true
let hasGrape = fruits.includes(‘grape’);
// hasGrape is false, as ‘grape’ is not in the array

 

NOTE:

  • Thank you for taking the time to read this post. I hope you found it insightful and informative.  If you enjoyed this post, here are some additional resources you might find helpful:
  1. JavaTpoint
  2. Geeks for Geeks
  3. W3School
  4. Javascript.info
  5. Programiz
  6. MDN Documentation
  7. chatgpt

Feel free to share your thoughts or questions in the comments below. I love hearing from my readers!

 Stay curious and keep learning,

 [Decode Now]

 

SummarizeShare234
admin

admin

Related Stories

Mastering JavaScript Error Handling

Mastering JavaScript Error Handling

by admin
June 7, 2026
1

Mastering JavaScript Error Handling   Introduction: JavaScript, as a versatile and powerful programming language, has become the backbone of modern web development. However, like any programming language, it's...

JavaScript Closure

JavaScript Closure

by admin
June 16, 2026
0

Understanding JavaScript Closure JavaScript closures are a fundamental concept that plays a crucial role in the language's functionality. They enable developers to create powerful and flexible code structures...

Understanding JavaScript Hoisting

by admin
June 14, 2026
0

Understanding JavaScript Hoisting JavaScript hoisting is a crucial concept that affects how variables and functions are processed during the compilation phase before code execution. It refers to the...

Introducing JavaScript Object Methods

Introducing JavaScript Object Methods

by admin
June 16, 2026
0

JavaScript Object Methods In JavaScript, objects play a crucial role in representing real-world entities or concepts. They encapsulate data, known as properties or attributes, and the methods (actions...

Next Post
String-Methods-Javascript

Introducing JavaScript String Methods

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Decode Now

Learn. Build. Grow. Explore programming tutorials, development roadmaps, interview preparation guides, and career resources designed for aspiring developers.

Follow us

Recent Posts

JavaScript Document Object Model

JavaScript Document Object Model

June 7, 2026
JavaScript arrow functions & regular functions

JavaScript Arrow Functions & Regular Functions

June 7, 2026

Weekly Newsletter

  • Decode Now
  • Blogs
  • Contact US
  • About us

© 2026

No Result
View All Result
  • Home
  • Blog
    • AI
    • Backend
      • Java
    • Career & Interviews
    • Frontend
      • HTML
      • CSS
      • JavaScript
    • Full Stack
  • Notes
  • About us
  • Contact US

© 2026