728x90
SMALL
#Javascript
#JavaScript/Object/Array.length/Property that returns the length of the array
.length
.length is an attribute that returns the length of the array. Returns a number one greater than the index value of the last element. It has a different meaning than the number of elements belonging to the array.
grammar
array.length
example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript</title>
<style>
body {
font-family: Consolas, sans-serif;
font-style: italic;
}
</style>
</head>
<body>
<script>
var jbAry1 = [ 1, 2, 3, 4 ];
document.write( '<p>jbAry1.length : ' + jbAry1.length + '</p>' );
var jbAry2 = new Array();
jbAry2[10] = 1;
document.write( '<p>jbAry2.length : ' + jbAry2.length + '</p>' );
</script>
</body>
</html>
- The index value of the last element of array jbAry1 is 3, so jbAry1.length is 4.
- The index value of the last element of array jbAry2 is 10, so jbAry2.length is 11.
728x90
LIST