JavaScript gets the attributes and property values in the direct amount of the object

Source: Internet
Author: User

JavaScript gets the properties and property values in the object's direct volume:
The so-called direct amount of the object is simply a list of key-value pairs wrapped by braces, for example:

var antzone={  webName:"Ant Tribe",  Address:"Shinan District, Qingdao", age  :2}

Here's how to get the properties and property values in the object's direct amount, the code is as follows:

var antzone={  webName:"Ant Tribe",  Address:"Shinan District, Qingdao", age  :2 }for (var in antzone) {  Console.log (prop+ ":" +  Antzone[prop]);}

The above code implements our requirements and uses a for in loop to iterate through its properties, and more to read about it.
Related reading:
The 1.for in statement can be found in the section on the use of JavaScript for the in statement .
2.javascript objects can be found in several ways of creating objects in JavaScript section.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=12199

For more information, refer to: http://www.softwhy.com/javascript/

JavaScript gets the attributes and property values in the direct amount of the object

Related Article

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.