For a summary of the JavaScript length attribute, please see the following details.
Length in the Stringobject
The Length property is the number of characters that return a string.
For example:
Ordinary string
var str = "abcdef";
Console.log (str.length); 6
//array
var str1 = new Array (1,2,3,4);
Console.log (str1.length); 4
//array with string
var str2 = str1 + str;//"abcdef1,2,3,4"
Console.log (str2.length);///
object and Object
V Ar obj = {};
Console.log (obj.length); Undefined
var obj + = obj;//"[Object Object][object Object]"
console.log (obj.length);//30
Length in function
Length can return the number of parameters for a function.
var a = function (a,b,c,d) {};
Console.log (a.length); 4
var b = RegExp;
Console.log (b.length); The new REGEXP (pattern, attributes) construction method has two parameters, so length is 2
The length property of the ※arguments instance returns the number of actual arguments passed to the function by the calling program.
var a = function () {
console.log (arguments.length);
};
A (1,2,3); 3
A ();//0
Note: As we all know, there are no overloads of methods in JavaScript, and arguments instances can help us simulate the overloads of methods.
The following is an example to introduce the JavaScript length property
Definitions and usage
The Length property can return the number of characters in the string.
Grammar
Stringobject.length
Instance
In this case, we'll show you how to use the Length property to return the number of characters in a string:
<script type= "Text/javascript" >
var txt= "Hello world!"
document.write (txt.length)
</script>
Output:
12
The above is about the JavaScript Length property summary of the entire content, I hope you like.