JavaScript Array
The array is a data structure that is used to store data in a sequential manner of the same type. Arrays allow duplication of data and data is indexed which means that the data can be accessed according to its unique index.
Syntax:
let arrayName = [value1, value2, ...]; // Method 1
let arrayName = new Array(); // Method 2
Example: In this example, we will implement an array and access its element.
Javascript
let sample = new Array(); sample.push( "Hello" ); sample.push( "1" ) sample.push( "Bye" ) sample.push( "@" ); console.log(sample); console.log(sample[3]) |
[ 'Hello', '1', 'Bye', '@' ] @
Set vs Array in JavaScript
In JavaScript, Set and Array are common data structures used to store collections of data. These data structures are different because of their unique features. Let us look at the implementation of both of these data structures.