Home >Web Front-end >JS Tutorial >The difference between jquery length and size()

The difference between jquery length and size()

coldplay.xixi
coldplay.xixiOriginal
2020-12-01 16:18:453731browse

The difference between jquery length() and size(): 1. length is an attribute, and size is a method; 2. The values ​​obtained by length and size are the same, but if you want to get the length of a string, you have to use length.

The difference between jquery length and size()

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

The difference between jquery length() and size():

1. The difference in identity, basic_string<> has dual identities. One is to replace the traditional C string, so the corresponding function length should be given for strlen in C. Another identity can be used as an STL container, so size() is given as per the convention for STL containers.

2. The difference in type is that length is an attribute and size() is a method.

3. The difference in usage is that if you just want to get the number of elements, the effect is the same. The values ​​obtained by length and size() are the same; but if you want to get the length of the string, you have to Use length.

4. The difference in encoding. The actual situation is that the length() method returns the number of character code units encoded in UTF-16, which is not necessarily the actual number of characters we think. Similarly, the codePointCount() method returns the number of code points, which is the actual number of characters.

Because commonly used uniCode characters can be represented using one code unit, but some auxiliary characters require a pair of code units to be represented. The length() method calculates the number of code units, and the codePointCount() method calculates the number of code points.

5. Regarding the difference between objects, the length() method in java is for the string String. If you want to see the length of the string, use the length() method. The size() method in .java is for generic collections. If you want to see how many elements this generic has, call this method to view it.

Related free learning recommendations: javascript (video)

The above is the detailed content of The difference between jquery length and size(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn