Jquery map and get method details

  • 2020-03-26 23:07:55
  • OfStack

var arrayObj=["www","xxx","ddd"];
var ww=$.map(arrayObj,function(i){
                      return i;

var tt=$(":checkbox").map(function(){
                     return this.value;

JQuery has a concept called a "class Array", such as $(":checkbox"). When a collection is fetched, it has some properties of the Array, but instancseof Array is still false. But var a=$("li").get (), and then instancseof Array returns true.

Map () has two main steps, the first is traversal, the second is substitution.

For instanceof and typeof, I used them occasionally before, especially for typeof. Today, when I studied ext source code, instanceof was used in many places. I suddenly felt that they were somewhat similar but should have their differences.

Both instanceof and typeof can be used to determine whether a variable is null or of what type.
Typeof is used to get the typeof a variable. Generally, typeof can only return the following results: Number, Boolean, string, the function, object, undefined . We can use typeof to get whether a variable exists, such as if(typeof a! ="undefined"){}, do not use if(a), because if a does not exist (undeclared) will be an error, for the Array,Null and other special objects use typeof return object, this is the limitation of typeof.

With respect to instanceof, we will insert one more issue, that is, arguments for function. We may all think arguments is an Array, but if we test it with instaceof, arguments are not an Array object, although they look similar.

Related articles: