Summary of length properties in JavaScript
Length in the Stringobject
The length property is the number of characters that return a string.
For example:
//Normal Stringvarstr = "ABCdef"; Console.log (str.length);//6//ArrayvarSTR1 =NewArray (1,2,3,4); Console.log (str1.length); //4//Arrays and StringsvarSTR2 = str1 + str;//"abcdef1,2,3,4"Console.log (str2.length);// -//Objects and Objectsvarobj ={};console.log (obj.length);//undefinedvarobj + = obj;//"[Object Object][object Object]"Console.log (obj.length);// -
Length in function
Length returns the number of arguments to function.
var function /// 4var b=//new RegExp (pattern, attributes) construction method has two parameters, So length is 2
※ The length property of the arguments instance is the number of actual arguments that are returned by the calling program to the function.
var function () { console.log (arguments.length);}; A (// 3// 0
Note: It is well known that there are no overloads of methods in JavaScript, and arguments instances can help us to simulate overloads of methods.
Summary of length properties in JavaScript