Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Array Reference

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 06 Jan, 2023
Improve Article
Save Article

JavaScript Array is used to store multiple elements in a single variable. It is often used when we want to store a list of elements and access them by a single variable. Unlike most languages where the array is a reference to the multiple variables, in JavaScript array is a single variable that stores multiple elements.

Syntax:

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

Example: In this example, we are creating an array and copying its items to another array, and displaying its items.

JavaScript




<script>
    // Create and initialize an array
    let items = ['GFG', 'Geeks', 'G4G'];
  
    // Display the array items
    console.log(items);
  
    // Create a new empty array
    let new_Array = [];
  
    // forEach loop to push elements
    // into new array
    items.forEach(function (item) {
        new_Array.push(item);
    });
  
    // Display the new array of items
    console.log(new_Array);
</script>

Output:

Original Array: GFG, Geeks, G4G
Copied Array: GFG, Geeks, G4G

JavaScript Array Methods: The complete list of JavaScript Array methods are listed below.

Methods

Descriptions

concat()This is used to merge two or more arrays together.
copyWithin()It considers an array first and then copies part of an array to the same array itself and returns 
entries()It is used to fetch all the entries of the same data structure.
every()checks that whether all the elements of the array satisfy the given condition 
fill()This is used to 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()It is used to 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.
from()It returns an Array object from any object with a length property or an iterable object.
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.
isArray()Returns true if the argument passed is an array else it returns false.
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()This function calls the argument function once for each element of the given array in order. 
of()It creates a new array instance with variables present as the argument of the function. 
pop()Remove the last element of the array and also returns the removed element.
push()This is used to 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()It 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()It 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. 

Array Property: The list of JavaScript Array properties are listed below.

Properties

Description

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

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!