xxxxxxxxxx
var arr = [10,20,30,40,50]; //An Array is defined with 5 instances
var len= arr.length; //Now arr.length returns 5.Basically, len=5.
console.log(len); //gives 5
console.log(arr.length); //also gives 5
xxxxxxxxxx
/*
Array Methods
- Length
*/
// Index Start From 0 [ 0, 1, 2, 3, 4 ]
let myFriends = ["Ahmed", "Mohamed", "Sayed", "Alaa"];
myFriends.length = 2;
console.log(myFriends);
xxxxxxxxxx
var x = [];
console.log(x.size());
console.log(x.length);
console.log(x.size()==x.length);
x =[1,2,3];
console.log(x.size());
console.log(x.length);
console.log(x.size()==x.length);
//arjun
xxxxxxxxxx
// get the length of an array
// define array
let numbers = [10, 20, 30, 40, 50]
let words = ['I', 'Love', 'Javascript']
// call the .length property ( DO NOT USE () after it)
number.length // 5
words.length // 3
xxxxxxxxxx
public class ArrayLengthExample1
{
public static void main(String[] args)
{
//defining an array of type int named num
//the square bracket contain the length of an array
int[] num = new int[10];
//length is an Array attribute that determines the array length
int arrayLength=num.length;
//prints array length
System.out.println("The length of the array is: "+ arrayLength);
}
}
xxxxxxxxxx
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits[fruits.length] = "Kiwi";