Tech Study

JavaScript Arrays with Examples

An JavaScript Arrays is a collection of homogeneous, contiguous, or related data elements that share a common name. Arrays are important data structures in programming and are used to store and manage lists of elements such as numbers, strings, objects, or other arrays. The array provides a suitable means of grouping related data. 

The number, called the record index, can either refer to an individual element of the JavaScript Arrays or to the index in Square brackets after the array name.

javascript arrays example

Example:

// Create an array of Fruits1

const Fruits1 = ["Apple", "Banana", "Orange", "Mango"];




for (let j = 0; j< Fruits1.length; j++) 

{

  console.log(Fruits1[j]);

}

Output:

Apple

Banana

Orange

Mango

To add new values to the array using:

// Create an array of Fruits1

const Fruits1= ["Apple", "Banana", "Orange", "Mango"];

// Add a new fruit to the array

Fruits1.push("Grapes");




for (let j = 0; j < Fruits1.length; j++) 

{

  console.log(Fruits1[j]);

}

Output:

Apple

Banana

Orange

Mango

Grapes

To delete values from array using:

// Create an array of Fruits1

const Fruits1 = ["Apple", "Banana", "Orange", "Mango"];




// Remove the last fruit from the array

Fruits1.pop();




for (let j = 0; j < Fruits1.length; j++) 

{

  console.log(Fruits1[j]);

}

Output:

Apple

Banana

Orange

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more