The Wayback Machine - https://web.archive.org/web/20230602103613/https://www.geeksforgeeks.org/javascript-array-reference/amp/

JavaScript Array Reference

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.




<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

 

 

The complete list of JavaScript Array is listed below:

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

Constructor

Descriptions

Examples

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.

JavaScript Array Methods: JavaScript methods are actions that can be performed on objects.


Article Tags :