For example:
$.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
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.
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
var obj={"a":0};var obj1={"a":0};
alert(obj==obj1);// false;--------- ------------
var obj={"a":0};
var obj1=obj;
alert(obj==obj1);
// true;