toLocaleString () toString () valueof () Three methods on the array of different applications

Source: Internet
Author: User

Digression: To determine whether an object is a problem that is not an array. For a Web page, or a global scope, the instanceof operator can be used to achieve satisfactory results:

if (value instanceof Array) {
}

The problem, however, is that the instanceof operator assumes that there is only one global execution environment. If a Web page contains more than one frame, there is actually more than two different global execution environments, so there are more than two different versions of the array constructor. If you pass an array to another frame from one frame, the passed-in array has its own different constructors than the array created in the second frame. To solve this problem, you can use the Array.isarray () method. The purpose of this method is to determine in the end whether a value is an array.


Conversion method:

As previously sued, all objects have the tolocalestring () ToString () valueof () method, where the call to the ToString () method of the array returns a comma-delimited string of strings of each value in the array. And the call to ValueOf () returns an array. In fact, in order to create this string, the ToString () method for each item of the array is invoked.

var colors=["Red", "Blue", "green"];

Alert (colors.tostring ()); Red,blue,green

Alert (colors.valueof ()); Red,blue,green

alert (colors); Red,blue,green


Because alert () receives a string parameter, he calls the ToString () method in the background, resulting in the same result as a direct call to the ToString () method. In addition, the tolocalestring () method often returns the same value as the valueof () and ToString () methods, but not always, when the toLocaleString () method of an array is invoked, it also creates a comma-delimited string of array values

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.