Home > Web Front-end > JS Tutorial > body text

Introduction to jQuery's inArray method_jquery

WBOY
Release: 2016-05-16 18:01:09
Original
1483 people have browsed it

For example:

Copy code The code is as follows:

$.get('aaaaa.ashx', null,function(d){
  // Assume that the value returned by d is 1,3,43,23,54,67
var arr = d.split(',');
 $.inArray (3,arr) ==-1 //true
//Why
//If it is written like this
var arr = eval('[' d ']');
$. inArray(3,arr) >-1 //true
});

Why is this? I hope friends who know will reply.
jquery inarray () Function detailed explanation
jquery.inarray(value,array)
Determine the position of the first parameter in the array (returns -1 if not found).

determine the index of the first parameter in the array (-1 if not found).
Return value
jquery
Parameter
value (any): used in the array Find if
array exists (array): the array to be processed.

A friend asked a question today, as follows
Copy the code The code is as follows:

var testarr=[{"a":"0"},{"b":"1"},{"c":"2"}];alert($.inarray({"a":" 0"},testarr));

Said that this value always returns -1;
At first glance, I didn’t notice it, so I wrote a paragraph for him to read.
Copy code The code is as follows:

var obj={'m':'1'} ;var arr=[obj,'1',2];alert($.inarray(obj,arr));

This return value is normal.
I realized later that the object is a reference type.
The characteristics of reference types can be demonstrated with a short program

Copy the code The code is as follows:

var obj={"a":0};var obj1={"a":0};
alert(obj==obj1);// false;--------- ------------
var obj={"a":0};
var obj1=obj;
alert(obj==obj1);
// true;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template