Program to use JavaScript Array length
let a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
let b = a.length;
console.log(b);
Output
5
Steps Description
- Declare two variable
a
andb
- Initialize two variable with value of array
a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant']
andb
- The
array length()
method outputs the index numbers of the array elements. - The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array length
let c = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
c.length = 3
console.log(c);
Output
[ 'Cat', 'Dog', 'Tiger' ]
Steps Description
- Declare variable
c
- Initialize variable with value of array
c = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant']
- The
array length()
method outputs the index numbers of the array elements. - The value of
c
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array length
let d = [1,2,3,4,5,6,7,8,9,10];
let e = d.length;
console.log(e);
Output
10
Steps Description
- Declare two variable
d
ande
- Initialize two variable with value of array
d = [1,2,3,4,5,6,7,8,9,10]
ande = d.length
- The
array length()
method outputs the index numbers of the array elements. - The value of
e
variable is displayed with the help of console.log inbuilt function