30
loading...
This website collects cookies to deliver better user experience
length
property which returns the number of elements or in other words, size of an array. let petsArr = ['cats','dogs','cows','fishes','birds'];
console.log(petsArr.length);
//output: 5
let petsArr = [
'cats',['bulldog','husky'],'cows','fishes',
{bird1: 'crow', bird2: 'parrot'}
];
console.log(petsArr.length);
//output: 5
How to Access the Array Elements
in JavaScript.square brackets []
.arrayName[];
let numArr = [50,60,70];
console.log(numArr[0]); //output 50
let data = numArr[1];
console.log(data); //output 60
let numArr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
console.log(numArr[3]); //output [[10,11,12], 13, 14]
console.log(numArr[3][0]); //output [10,11,12]
console.log(numArr[3][0][1]); //output 11