1. Introduction
Array is a unique kind of variable which can store multiple values. It is enclosed in square [] brackets.
Syntax
const variable_name= [//"data"];
2. Its importance
Array is very helpful as it makes our work easier and also make code less complicated and simple. We don't need to create multiple variables as we can store multiple kind of data in one.
NOTE
We can modify the data in array once declared.
3. Array length
We can access the no of items in the array using 'length' keyword.
For example:
const cars= ['BMW', 'Audi', 'Mercedes'];
console.log(cars.length)
Output for above example is:
3 is output, as there are three items in the array.
Example:
const laptops = ['Lenovo', 'Dell', 'HP'];
console.log(laptops.length)
output:
3
4. Array Push
Array Push adds the item at the end of the sequence.
For example:
const fruits= ['Apple', 'Mango', 'Banana'];
fruits.push('Orange');
console.log(fruits)
Output:
["Apple", "Mango", "Banana", "Orange"]
In above example, an array named fruits was created and in statement 2, using push keyword, 'orange' was added in the list.
Top comments (0)