Horje
How to Create Different Types of Arrays in JavaScript ?

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);



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
How to Concatenate Two Variables in JavaScript ? How to Concatenate Two Variables in JavaScript ?
What is the use of the Math.random Function in JavaScript ? What is the use of the Math.random Function in JavaScript ?
How to Check if a Variable is of Type Number in JavaScript ? How to Check if a Variable is of Type Number in JavaScript ?
How to Create a Single Line Comment in JavaScript ? How to Create a Single Line Comment in JavaScript ?
How to Create a Multi Line Comment in JavaScript ? How to Create a Multi Line Comment in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13