For example:
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 is that?
If it is written like this
var arr = eval (' [' +d+ '] ');
$.inarray (3,arr) >-1//true
});
What is this for? Hope to know the friend keep abreast reply under.
The jquery InArray () function is detailed
Jquery.inarray (Value,array)
Determines 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
Parameters
Value (Any): used to find the existence of an array
Array: Arrays to be processed.
Today, a friend asked a question, as follows
The code is as follows:
var testarr=[{"A": "0"},{"B": "1"},{"C": "2"}];alert ($.inarray ({"A": "0"},testarr));
Say this value always returns-1;
At first glance, I did not notice, so I wrote a paragraph for him to see.
The code is as follows:
var obj={' m ': ' 1 '};var arr=[obj, ' 1 ', 2];alert ($.inarray (Obj,arr));
This return value is normal.
It was later realized that the object was a reference type.
The attributes of a reference type can be demonstrated with a short program
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
Introduction to the Inarray method of jquery