What is an Array?
In JavaScript, An Array is a data structure that contains a list of elements. These elements are of the same data types. Such as integer or string.
Syntax:
let arrayname=[ ];let arrayname=new();
Example:
let car=["BMW","Merc"];
Using keyword new:
syntax:
let arrayname=new Array();
Example:
let car=new Array("BMW","Merc");
Access the Elements from Array:
We can access the array element by their index
Example:
let a=car[0];console.log(a);
Properties of Array:
There are some properties of an Arrays in Javascript
1.lenght
2.Prototype
Methods of Array:
1.concat() : it used to concat tow arrays.
2.find(): it is used to find an element in an Array.
3.filter(): Creates a new array with every element in an array that passes a test.
4.isArray(): Checks whether an object is an array.
5.Pop(): Delete the Array Element.
6.Push(): Insert the array element.
7.sort(): Sort Array list.
8.reverse(): to reverse the array.
Example:
let a=[1,2,3,4]; let b=new Array(2,3,7,8); console.log(a); console.log(b); console.log("Lenth of Array a is",a.length);//property of Array let c=a.concat(b); console.log("Concat",c); a.push(7); console.log("After Push",a) console.log(a.reverse()) console.log(a.sort())
Output:
(4) [1, 2, 3, 4]Lenth of Array a is 4
Concat (8) [1, 2, 3, 4, 2, 3, 7, 8]
After Push (5) [1, 2, 3, 4, 7]
(5) [7, 4, 3, 2, 1]
(5) [1, 2, 3, 4, 7]
Comments
Post a Comment
If you have any query, please let us know