JavaScript Arguments class Array

Source: Internet
Author: User

1. What is an array of classes

  Arguments is a class array object. Represents a list of arguments passed to a function.

Let's pass an example.

 function Printargs () {

console. Log(arguments);

}

Printargs ("A", "a", 0, {foo: "Hello, Arguments"});

["A", "A", 0, Object]

Then look at what arguments represents, which represents all the arguments passed into the function when the function executes. In the above example, represents the incoming Printargs function in the four parameters, you can use Arguments[0], arguments[1] ... To get the individual parameters .

2. Operation of the arguments

 Arguments.length

arguments is a class array object that contains a length property that can be used arguments.length to get the number of arguments passed into the function.

arguments to an array .

Array.prototype.silce.call (arguments); or use [].slice.call (arguments);

Modify the arguments value .

function foo(a) {

"Use strict";

console. Log(a, arguments[0]);

a = ten;

console. Log(a, arguments[0]);

arguments[0] = ;

console. Log(a, arguments[0]);

}

Foo(1);

// 1 1//10 1//10 20

Examples of non-strict patterns:

function foo(a) {

console. Log(a, arguments[0]);

a = ten;

console. Log(a, arguments[0]);

arguments[0] = ;

console. Log(a, arguments[0]);

}

Foo(1);

// 1 1//10 10//20 20

In strict mode, the arguments in the function are not associated with the arguments object, and modifying one value does not change the other. In non-strict mode, the two affect each other.

3. array and class array objects

An array has one basic characteristic: an index. This is not the general object.

Const OBJ = {0: "A", 1: "B"};

Const ARR = ["A", "B"];

We use obj[0], arr[0] to get the data we want, but the way we get the data is really different. OBJ[0] is the use of the object's key-value pairs to access data, while Arr[0] is the index of the use of the array. In fact, the only difference between an object and an array is that the property of object is a string, and the index of the array is number.

Here's a look at the class array object.

the characteristic of a pseudo-array is that it looks like an array, contains a set of data, and has a length property, but does not have any method of array. In particular, the length property is a nonnegative integer, the upper limit is the maximum number that can be accurately expressed in JavaScript, and the length value of the class array object cannot be changed automatically .

  

JavaScript Arguments class Array

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.