Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Array (Array) in JavaScript

Explore Array (Array) in JavaScript with clear explanations, practical examples, and useful tips.

Table of Contents

This guide covers array (array) in JavaScript with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

Syntax

Use the following syntax to create an Array Object:

 var fruits = new Array ( "apple" , "orange" , "mango" ); 

The Array parameter is a list of strings or integers. When you define a single numeric parameter with the Array constructor, you specify the initialization length of the array. The maximum permitted length for an array is 4, 294, 967, 295.

You can create an array by simply assigning the following values:

 var fruits = [ "apple" , "orange" , "mango" ]; 

You will use the sequence number to access and set the values inside an array as follows:

 fruits [ 0 ] is the first element fruits [ 1 ] is the second element fruits [ 2 ] is the third element 

Array Properties

Here are the properties of the Array object and their description.

Properties Description

Constructor

Returns a reference to the array function that creates that object. Index The property represents the zero-based index of the match in the string. Input This attribute is present only in arrays created by regular Expression matches.

Length

Reflect the number of elements in an array.

Prototype

The prototype property allows you to add properties and methods to an object.

Array Methods

Below is a list of the methods of the Array object along with their description.

Method Description

Concat ()

Returns a new array that includes this array in combination with other arrays and / or values.

Every ()

Returns true if each element in this array satisfies the given test function.

Filter ()

Create a new array with all elements of this array, for which the filter function returns true.

ForEach ()

Call a function for each element in the array.

IndexOf ()

Returns the first (lowest) index of an element in the array equivalent to the given value, or -1 if not found.

Join ()

Combine all elements in an array into a string.

LastIndexOf ()

Returns the last (largest) index of an element in the array equivalent to the given value, or -1 if not found.

Map ()

Create a new array with the results of calling a given function on each element of this array.

Pop ()

Remove the last element from an array and return that element.

Push ()

Add one or more elements to the end of an array and return the new length of the array.

Reduce ()

Apply a function simultaneously with two values of the array (from left to right) when reducing it to a single value.

ReduceRight ()

Apply a function simultaneously with two values of the array (from right to left) when it is reduced to a single value.

Reverse ()

Reverse the order of the elements of an array - First become the last and finally become the first.

Shift ()

Remove the first element from an array and return that element.

Slice ()

Extract - extract an area of an array and return a new array.

Some ()

Returns true if at least one element in this array satisfies the given test function.

ToSource ()

Represents the source code of an object.

Sort ()

Arrange the elements of an array.

Splice ()

Add and / or remove elements from an array.

ToString ()

Returns a string representing the array and its elements.

Unshift ()

Add one or more elements to the beginning of an array and return the new length of the array.

According to Tutorialspoint

Previous article: String object in JavaScript

Next lesson: Date object in JavaScript

FAQ

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.