Skip to content

WebDevHubs

  • Home
  • HTML
  • CSS
  • JavaScript
  • Web Technologies
  • Web Templates
  • Toggle search form

JavaScript Array Methods

Posted on December 4, 2024December 18, 2024 By Admin No Comments on JavaScript Array Methods

JavaScript Array Methods provide powerful built-in functions to perform operations on array. These methods simplifies the operations like – adding, removing, searching, sorting, filtering, and other operations.

Here is an example that demonstrates the basic array operations.

// Initial array of numbers
let arr = [10, 20, 30, 40, 50];

// 1. Adding numbers to the array
arr.push(60); // Add 60 at the end
arr.unshift(5); // Add 5 at the beginning
console.log("After Adding Elements:", arr);
// Output: After Adding Elements: [ 5, 10, 20, 30, 40, 50, 60 ]


// 2. Filtering numbers greater than 50
let nums = arr.filter(num => num <= 30);
console.log("Numbers Less Than or Equal to 50:", nums);
// Output: Numbers Less Than or Equal to 50: [ 5, 10, 20, 30 ]


// 3. Doubling the values
let doubledNums = arr.map(num => num * 2);
console.log("Doubled Values:", doubledNums);
// Output: Doubled Values: [ 10,  20,  40, 60, 80, 100, 120 ]


// 4. Sorting in Descending Order
let sortedNums = arr.sort((a, b) => b - a);
console.log("Sorted in Descending Order:", sortedNums);
// Output: Sorted in Descending Order: [ 60, 50, 40, 30, 20, 10,  5 ]

Below are the list of all JavaScript array methods with their brief description.

Method/PropertyDescription
JavaScript Array() constructorCreates a new array instance (Array object).
JavaScript Array.from() MethodCreates an array from an array-like or iterable object.
JavaScript Array.fromAsync() MethodCreates an array from an async iterable or promises.
JavaScript Array.isArray() MethodChecks if a value is an array.
JavaScript Array.of() MethodCreates an array from arguments provided.
JavaScript Array at() MethodReturns the element at a specific index, supporting negative indices.
JavaScript Array concat() MethodMerges two or more arrays into a new array.
JavaScript Array copyWithin() MethodCopies part of an array to another location within the same array.
JavaScript Array entries() MethodReturns an iterator with key-value pairs for array indices and values.
JavaScript Array every() MethodTests if all elements pass a given condition.
JavaScript Array fill() MethodFills elements with a static value from a start to an end index.
JavaScript Array filter() MethodCreates a new array with elements that pass a condition.
JavaScript Array find() MethodReturns the first element that satisfies a condition.
JavaScript Array findIndex() MethodReturns the index of the first element that satisfies a condition.
JavaScript Array findLast() MethodReturns the last element that satisfies a condition.
JavaScript Array findLastIndex() MethodReturns the index of the last element that satisfies a condition.
JavaScript Array flat() MethodFlattens nested arrays into a single-level array.
JavaScript Array flatMap() MethodMaps and flattens the array in one operation.
JavaScript Array forEach() MethodExecutes a function for each array element.
JavaScript Array includes() MethodChecks if an array contains a specified value.
JavaScript Array indexOf() MethodReturns the index of the first occurrence of a value.
JavaScript Array join() MethodJoins all elements into a string using a specified separator.
JavaScript Array keys() MethodReturns an iterator for the array indices.
JavaScript Array lastIndexOf() MethodReturns the index of the last occurrence of a value.
JavaScript Array map() MethodCreates a new array by applying a function to each element.
JavaScript Array pop() MethodRemoves and returns the last element of an array.
JavaScript Array push() MethodAdds one or more elements to the end of an array.
JavaScript Array reduce() MethodReduces the array to a single value using a function.
JavaScript Array reduceRight() MethodReduces the array to a single value, iterating from right to left.
JavaScript Array reverse() MethodReverses the order of array elements.
JavaScript Array shift() MethodRemoves and returns the first element of an array.
JavaScript Array slice() MethodReturns a shallow copy of part of an array.
JavaScript Array some() MethodTests if at least one element passes a given condition.
JavaScript Array sort() MethodSorts the array in place based on a comparison function.
JavaScript Array splice() MethodAdds or removes elements from an array at a specified index.
JavaScript Array toLocaleString() MethodConverts elements to strings using locale settings.
JavaScript Array toReversed() MethodReturns a new array with reversed elements without modifying the original array.
JavaScript Array toSorted() MethodReturns a new array with sorted elements without modifying the original array.
JavaScript Array toSpliced() MethodReturns a new array after splicing, without modifying the original array.
JavaScript Array toString() MethodConverts the array to a string of elements separated by commas.
JavaScript Array unshift() MethodAdds one or more elements to the beginning of an array.
JavaScript Array values() MethodReturns an iterator for the array values.
JavaScript Array with() MethodReturns a new array with an updated value at a specified index.
JavaScript Array length PropertyReturns the number of elements in the array.

JavaScript, Web Technologies Tags:JavaScript-Array, JavaScript-Array-Method

Post navigation

Previous Post: Array in JavaScript
Next Post: JavaScript Array indexOf() Method

Leave a Reply Cancel reply

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

Archives

  • June 2025
  • May 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024

Categories

  • CSS
  • HTML
  • JavaScript
  • Lodash
  • PHP
  • Python
  • Web Technologies
  • Web Templates

Recent Posts

  • JavaScript Array isArray() Method
  • JavaScript Array forEach() Method
  • JavaScript Array includes() Method
  • JavaScript Array keys() Method
  • JavaScript Array lastIndexOf() Method

Recent Comments

No comments to show.

Copyright © 2025 WebDevHubs.

Powered by PressBook Green WordPress theme