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
<html>
<head>
<title>JavaScript Array length Property</title>
</head>
<body>
<script type = "text/javascript">
var arr = new Array( 10, 20, 30 );
document.write("arr.length is : " + arr.length);
</script>
</body>
</html>
/*
Array Methods
- Length
*/
// Index Start From 0 [ 0, 1, 2, 3, 4 ]
let myFriends = ["Ahmed", "Mohamed", "Sayed", "Alaa"];
myFriends.length = 2;
console.log(myFriends);
//The length property provides an easy way to append a new element to an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits[fruits.length] = "Kiwi"
// >> ["Banana", "Orange", "Apple", "Mango" , "Kiwi"]
//if you find this answer is useful ,
//upvote ⇑⇑ , so the others can benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits[fruits.length] = "Kiwi";
int a[20];
int length;
length = sizeof(a) / sizeof(int);
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);
}
}
const dailyActivities = [ 'eat', 'sleep'];
// this gives the total number of elements in an array
console.log(dailyActivities.length); // 2