Open In App

How to Create Different Types of Arrays in JavaScript ?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In JavaScript, you can create an array using square brackets [] and optionally initialize it with values. Here are a few examples:

  1. Empty Array:
    • Create an empty array.
    let emptyArray = [];
  2. Array with Values:
    • Initialize an array with values.
    let numbers = [1, 2, 3, 4, 5];
    let fruits = ["Apple", "Banana", "Orange"];
  3. Mixed Data Types:
    let mixedArray = [1, "two", true, { key: "value" }];
  4. Using the Array Constructor:
    • You can also use the Array constructor to create an array.
    let newArray = new Array();
    let arrayWithValues = new Array(1, 2, 3, 4, 5);

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads