5th Chapter Reference Types

Source: Internet
Author: User

This chapter contains the object type, date type, regexp type, function type, basic wrapper type, and monomer built-in object.

A value (object) of a reference type is an instance of a reference type, which is a data structure. var person = new Object (); The new operator instantiates an object, and the instantiated object defines the default properties and methods.

5.1 Object Type

There are two ways to create an OBJECR instance. The first uses the New+object constructor:

var person = new Object;

Person.name = "Nicholas";

person.age = 29;

Another way is to use the object literal:

var person={

Name:nicholas,

Age:29

};

Use commas to separate different attributes, not commas after the last property

5.2 Array Type

There are two types of array creation

var arr = new Array ();

var arr=[];

The last index of an array is always length-1

The array length property is not read-only, you can add a new item to the array or remove an item from the end of the array by setting this property

5.2.1 Detecting arrays

The instanceof operator can only act on a global execution environment, with Arry.isarray () when a page contains multiple frames

5.2.2 Conversion method

Array inheritance tolocalestring (), toString (), valueof () methods

The Join method reproduces ToString (), separates the different delimiters, and returns the array as a string.

var num = [1, 2, 3];

Alert (num.join (' | ')); Output 1|2|3

5.2.3 Stack method

An array can be like a stack, which is a data structure that can restrict the insertion and deletion of items. Maintain the principle of LIFO.

The insertion or removal of an array is only found at the top of the stack.

A) push () is added to the end of the array

b) Pop () removes the last item from the end of the array and then returns the removed item

5.2.4 Queue method

5th Chapter Reference Types

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.