Thursday, October 13, 2022
HomeWordPress DevelopmentIntro to Array in JavaScript.

Intro to Array in JavaScript.


1. Introduction
Array is a novel sort of variable which might retailer a number of values. It’s enclosed in sq. [] brackets.

Syntax

const variable_name= [//"data"];
Enter fullscreen mode

Exit fullscreen mode

2. Its significance
Array may be very useful because it makes our work simpler and in addition make code easier and easy. We needn’t create a number of variables as we are able to retailer a number of sort of knowledge in a single.
NOTE
We will modify the information in array as soon as declared.
3. Array size
We will entry the no of things within the array utilizing ‘size’ key phrase.
For instance:

const vehicles= ['BMW', 'Audi', 'Mercedes'];
console.log(vehicles.size)
Enter fullscreen mode

Exit fullscreen mode

Output for above instance is:
3 is output, as there are three objects within the array.
Instance:

const laptops = ['Lenovo', 'Dell', 'HP'];
console.log(laptops.size)
Enter fullscreen mode

Exit fullscreen mode

output:
3
4. Array Push
Array Push provides the merchandise on the finish of the sequence.
For instance:

const fruits= ['Apple', 'Mango', 'Banana'];
fruits.push('Orange');
console.log(fruits)
Enter fullscreen mode

Exit fullscreen mode

Output:
[“Apple”, “Mango”, “Banana”, “Orange”]
In above instance, an array named fruits was created and in assertion 2, utilizing push key phrase, ‘orange’ was added within the record.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments