JavaScript Objects---Recursive traversal of objects

Source: Internet
Author: User
Tags hosting

All things in JavaScript are objects: strings, numbers, arrays, functions ...

In addition, JavaScript allows custom objects to be customized.

JavaScript objects

JavaScript provides multiple built-in objects, such as String, Date, Array, and so on.

Objects are just special data types with properties and methods.

In ECMAScript, the physical representation of an object cannot be accessed, and only references to the object can be accessed. Every time you create an object, it is stored in a variable and is a reference to that object, not the object itself.

Local objects

ECMA-262 defines local objects (native object) as "objects provided by ECMAScript implementations that are independent of the hosting environment." In simple terms, a local object is a class defined by ECMA-262 (reference type). They include:

    • Object
    • Function
    • Array
    • String
    • Boolean
    • Number
    • Date
    • Regexp
    • Error
    • Evalerror
    • Rangeerror
    • Referenceerror
    • SyntaxError
    • TypeError
    • Urierror
Built-in objects

ECMA-262 defines the built-in object (built-in object) as "all objects that are provided by the ECMAScript implementation, independent of the hosting environment, and appear when the ECMAScript program starts executing." This means that the developer does not have to instantiate the built-in object explicitly, it has been instantiated. ECMA-262 only defines two built-in objects, Global and Math (they are also local objects, by definition, each built-in object is a local object).

Host Object

All non-local objects are host objects (host object), which is the object provided by the hosting environment implemented by ECMAScript.

All BOM and DOM objects are host objects.

varobj ={a:{Name:"Maoguotao", Age:18, Sex:M,}, b:{name:"Maoshuqin", Age:18, Sex:M,}, c:{name:"MGT360124", Age:18, Sex:M, Title: {job:Monitor                    }                 }             }; //recursively traverse an object            vararr = []; functionf (obj) { for(varIinchobj) {                     if(typeofObj[i] = = = "Object") {f (obj[i]); }Else{Arr.push (obj[i]);                        }}} f (obj); Console.log (arr);//["Maoguotao", "M", "Maoshuqin", "M", "MGT360124", "M", "Squad Leader"]

JavaScript Objects---Recursive traversal of 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.