Outdoor Adventure
  • Home
  • About
  • Contact
No Result
View All Result
Outdoor Adventure
  • Home
  • About
  • Contact
No Result
View All Result
Outdoor Adventure

Introducing JavaScript Array Methods

admin by admin
May 7, 2024
in Uncategorized
A A
JavaScript Array Methods
Share on FacebookShare on Twitter

Last Updated on May 7, 2024 by

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.

 

Related Post

Mastering JavaScript Error Handling

Mastering JavaScript Error Handling

August 10, 2024
Understanding JavaScript Closures

Understanding JavaScript Closure

August 1, 2024
Javascript Hoisting

Understanding JavaScript Hoisting

July 16, 2024
JavaScript Object methods

Introducing JavaScript Object Methods

June 1, 2024

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]

 

admin

admin

Related Posts

Mastering JavaScript Error Handling
Uncategorized

Mastering JavaScript Error Handling

by admin
August 10, 2024
Understanding JavaScript Closures
Uncategorized

Understanding JavaScript Closure

by admin
August 1, 2024
Javascript Hoisting
Uncategorized

Understanding JavaScript Hoisting

by admin
July 16, 2024
Next Post
String-Methods-Javascript

Introducing JavaScript String Methods

JavaScript Object methods

Introducing JavaScript Object Methods

Leave a Reply Cancel reply

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

  • Trending
  • Comments
  • Latest
JavaScript Variables

JavaScript Variables – Decode Now

March 11, 2024
Javascript Roadmap

Best Javascript Roadmap 2024

September 15, 2024
Understanding JavaScript Closures

Understanding JavaScript Closure

August 1, 2024
JavaScript Operators

JavaScript Operators – Decode Now

March 11, 2024
HTML Roadmap

Best HTML Roadmap For Programmers

12
Javascript and its Features

Javascript and its Features

4
Mastering JavaScript Error Handling

Mastering JavaScript Error Handling

1
CSS Roadmap

Best CSS Roadmap 2024

0
Mastering JavaScript Error Handling

Mastering JavaScript Error Handling

August 10, 2024
Understanding JavaScript Closures

Understanding JavaScript Closure

August 1, 2024
Javascript Hoisting

Understanding JavaScript Hoisting

July 16, 2024
JavaScript Object methods

Introducing JavaScript Object Methods

June 1, 2024

About

The best Premium WordPress Themes that perfect for news, magazine, personal blog, etc.

Categories

  • Javascript
  • Roadmaps
  • Uncategorized

Tags

css html java javascript JavaScript Loops js roadmap

Recent Post

  • Mastering JavaScript Error Handling
  • Understanding JavaScript Closure
  • Purchase Now
  • Features
  • Demo
  • Support

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Landing Page
  • Buy JNews
  • Support Forum
  • Pre-sale Question
  • Contact Us

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.