GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • JS Tutorial
  • Web Tutorial
  • A to Z Guide
  • Projects
  • OOP
  • DOM
  • Set
  • Map
  • Math
  • Number
  • Boolean
  • Exercise
  • Introduction3 min read
  • Variables5 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — JavaScript Array Reference - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • JS Tutorial
  • Web Tutorial
  • A to Z Guide
  • Projects
  • OOP
  • DOM
  • Set
  • Map
  • Math
  • Number
  • Boolean
  • Exercise

JavaScript Array Reference

Last Updated : 23 Jul, 2025

JavaScript Array is used to store multiple elements in a single variable. It can hold various data types, including numbers, strings, objects, and even other arrays. It is often used when we want to store a list of elements and access them by a single variable.

Syntax:

const arr = ["Item1", "Item2", "Item3", ...];

Example: Creating an array and copying its items to another array, and displaying the copied items.

JavaScript
// Create and initialize an array
let courses = ["HTML", "CSS", "JavaScript", "React"];

// Display the array items
console.log(courses);
 
// Create a new empty array
let newArray = [];
 
// forEach loop to push elements
// into new array
courses.forEach(function (course) {
    newArray.push(course);
});
 
// Display the new array of items
console.log(newArray);

Output
[ 'HTML', 'CSS', 'JavaScript', 'React' ]
[ 'HTML', 'CSS', 'JavaScript', 'React' ]

JavaScript Array Constructor

In JavaScript, a constructor gets called when an object is created using the new keyword.

Constructor

Descriptions

Array()It is used to create an array.

JavaScript Array Properties

A JavaScript property is a member of an object that associates a key with a value.

Instance Property:

An instance property is a property that has a new copy for every new instance of the class.

Instance Properties



Descriptions



constructorReturns only reference of the function and does not return the name of the function.
lengthSet or return the number of elements in an array.


JavaScript Array Methods

JavaScript methods are actions that can be performed on objects.

Static Method:

If the method is called using the array class itself then it is called a static method.

Static Methods



Descriptions



from()Returns an array object from any object with a length property or an iterable object.
isArray()Returns true if the argument passed is an array else it returns false.
of()Creates a new array instance with variables present as the argument of the function.


Instance Method:

If the method is called on an instance of a array then it is called an instance method.

Instance Methods



Descriptions



at()Returns the element of that index
concat()Merge two or more arrays together.
copyWithin()Copies part of an array to the same array itself and returns.
entries()Fetch all the entries of the same data structure.
every()checks that whether all the elements of the array satisfy the given condition.
fill()Fill the array with a given static value.
filter()Builds a new array containing elements that satisfy a function's test.
find()Get the value of the first element in the array that satisfies the provided condition.
findIndex()Return the first index of the element in a given array that satisfies the provided testing function.
flat()Flatten an array, to reduce the nesting of an array.
flatMap()This is used to flatten the input array element into a new array.
forEach()It is provided a function once for each element of the array.
includes()If an array contains the certain value, it returns true.
indexOf()Return the first index at which a given element may be found, or -1 if it does not exist.
join()Join the elements of an array into a string.
keys()Return a new array iterator which contains the keys for each index in the given input array.
lastIndexOf()Return the last index at which a given element may be found, or -1 if it does not exist.
map()Calls the argument function once for each element of the given array in order.
pop()Remove the last element of the array and also returns the removed element.
push()Push one or more values into the array.
reduce()Reduce the array to a single value and executes a provided function for each value of the array.
reduceRight()Convert elements of the given array from right to left to a single value.
reverse()This is used for the in-place reversal of the array.
shift()Removes the first element of the array thus reducing the size of the original array by 1.
slice()Returns a new array containing a portion of the array on which it is implemented.
some()Each array element's callback function is run once.
sort()Sort an array in place in a given order according to the compare() function.
splice()Modify the contents of an array by removing the existing elements.
toLocaleString()Convert the elements of the given array to string.
toString()Return the string representation of the array elements.
unshift()Add one or more elements to the beginning of the given array.
values()Return a new array Iterator object that contains the values for each index in the array.
Comment

Explore

    JavaScript Basics
    • Introduction3 min read
    • Variables5 min read
    • Operators4 min read
    • Control Statements4 min read
    Array & String
    • Arrays6 min read
    • Array Methods4 min read
    • String5 min read
    • String Methods8 min read
    Function & Object
    • Functions4 min read
    • Function Expression3 min read
    • Function Overloading4 min read
    • Objects4 min read
    • Constructors4 min read
    OOP
    • OOP5 min read
    • Classes & Objects4 min read
    • Access Modifiers5 min read
    • Constructor4 min read
    Asynchronous JavaScript
    • Asynchronous2 min read
    • Callbacks4 min read
    • Promises4 min read
    • Event Loop3 min read
    • Async Await Fuction3 min read
    Exception Handling
    • Error and Exceptional Handling5 min read
    • Errors Throw & Try to Catch2 min read
    • Custom Errors2 min read
    • TypeError Invalid Array.prototype.sort argument1 min read
    DOM
    • DOM8 min read
    • DOM Elements3 min read
    • Custom Events4 min read
    • Addeventlistener5 min read
    Advanced Topics
    • Closure3 min read
    • Hoisting5 min read
    • Scope4 min read
    • Higher Order Functions7 min read
    • Debugging3 min read
    Courses
    • Placement 360 Course2 min read
    • MERN Full Stack Course2 min read
    • DSA and System Design Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.