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
var array = [1, 2, 3, 4, 5]; // array of size 5
var size = array.length; // add.length to get size
console.log('size : '+size);
//output: size : 5
xxxxxxxxxx
const xyz = ['bat', 'ball', 'mat', 'pad'];
console.log(xyz.length);
// Output: 4
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
<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>
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
for (let g = 0; g < not_restaurant.length; g++) {
checked = (data[i].id === not_restaurant[g].restaurant_id) ? 'checked' : '';
}
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