Summary of length properties in JavaScript

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.