JS Array

In JavaScript, an Array is a special variable used to store multiple values in a single variable. Arrays are dynamic, meaning their size can change, and they can hold different types of data.


Creating an Array:

  • Using Array Literal (Preferred way)
  • Using new Array() Constructor
  • Empty Array Initialization

Using Array Litera Example
let fruits = ["Apple", "Banana", "Cherry"];
Using new Array() Constructor Example
let numbers = new Array(1, 2, 3, 4);
Empty Array Initialization Example
let emptyArray = [];

Accessing Array Elements:

Array elements are accessed using index numbers (0-based indexing).

Example
let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[0]); // Apple
console.log(fruits[1]); // Banana

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.