Jquery's map and get Methods _ jquery-js tutorial

Source: Internet
Author: User
This article gives a detailed summary of jquery's map and get methods. If you need it, you can refer to it and hope to help you. The Code is as follows:


Var arrayObj = ["www", "xxx", "ddd"];
Var ww = $. map (arrayObj, function (I ){
Return I;
}). Join (",");
Console. log (ww );

Var tt = $ (": checkbox"). map (function (){
Return this. value;
}). Get (). join (",");

Console. log (tt );


JQuery has a concept called "class Array", for example, $ (": checkbox"). When a set is obtained, some attributes of the Array are available, but the instancseof Array is still false. But var a = $ ("li"). get () and then instancseof Array returns true.

The map () function mainly involves two steps: the first step is traversal, and the second step is replacement.

For instanceof and typeof, We have occasionally used it before, especially for typeof. Today we are studying the ext source code and using instanceof in many places, I suddenly felt that the two of them were similar, but they should have their differences. I read some articles on the Internet and have a certain understanding of the relationship between them.

Both instanceof and typeof can be used to determine whether a variable is null or of any type.
Typeof is used to obtain the type of a variable. Generally, typeof can only return the following results:Number, boolean, string, function, object, undefined. We can use typeof to obtain whether a variable exists, such as if (typeof! = "Undefined") {}, instead of using if (a) because if a does not exist (not declared), an error occurs. For Array, null and other special objects use typeof to return all objects, which is the limitation of typeof.

If you want to obtain whether an object is an array or determine whether a variable is an instance of an object, you must use instanceof. Instanceof is an instance used to determine whether a variable is an Object, such as var a = new Array (); alert (a instanceof Array); true is returned, and alert (a instanceof Object) true is returned, because the prototype of Array is Object. For example, function test () {}; var a = new test (); alert (a instanceof test) returns true.

When talking about instanceof, We need to insert another question: function arguments. We may all think that arguments is an Array. However, if we use instaceof to test, we will find that arguments is not an Array object, although it looks very similar.

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.