Fast learning JavaScript objects-traversing objects

Source: Internet
Author: User

To make it easy to understand the methods that each JavaScript object contains, I write a function.

1 functiongetcollection (obj) {2     Try{3         if(obj) {4             varStype= "";5             varSmessage= "";6              for(varIinchobj) {7                 if(Obj[i] = = =NULL|| Obj[i] = = =undefined) {8Stype= "I";9smessage + = "\ r \ n" +i;Ten                 } One                 Else{ A                     varc =Obj[i]; -                     if(C.name &&c.value) { -smessage + = "\ r \ n" + (C.name + ":" +c.value); theStype= "Name:value"; -                     } -                     Else{ -smessage + = "\ r \ n" + (i + "=" +obj[i]); +Stype= "Obj[i]"; -                     } +                 } A             } atsmessage + = "\ r \ n" + ("Stype:" +stype); - alert (smessage); -         } -     } -     Catch(err) { -Alert ("ERR:" +err.message); in     } -}
View Code

For example, look at the location of all methods and values, can be called by the following JS

GetCollection (location);

The Popup interface is as follows:

You can also view the contents of a JSON : Var json ={"name": "Zhang San", "Depart": "Sales department", "Skill": ["Java", "C + +", "PHP", "C #"]};
GetCollection (JSON);

To view the contents of an array :

var arry =["1", "5", "C"];
GetCollection (Arry);

Fast learning JavaScript objects-traversing objects

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.