On JS use [] To access object Properties _javascript Tips

Source: Internet
Author: User

The properties of an object are accessed by two fixed methods: "." Notation and "[]" Square bracket notation:

Use the "." The notation accesses the standard object properties and uses the [] bracket notation to access the object properties defined by the page. As follows

document.forms["Myformname"].elements["Myinput"].value

Here, forms is a standard attribute of document, while table Single-name Myformname is defined by the page. Also, the elements and Value properties are standard attributes defined by the specification. and myinput is defined by the page.

If an attribute name is generated in execution, the square brackets are required if you have "Value1″," Value2″, and "Value3″ such attributes, and would like to use variable i=2 to access

This can be run:

myobject["value" +i]

This can not be:

Myobject.value+i

The above is a small series for you to bring the introduction of JS use [] to access the entire content of object properties, I hope to help you, a lot of support cloud Habitat Community ~

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.