The following describes how to use the inArray () function in jquery:
The Code is as follows:
$. Get ('aaaaa. ashx', null, function (d ){
// Assume that the value returned by d is 1, 3, 54,67.
Var arr = d. split (',');
$. InArray (3, arr) =-1 // true
// Why?
// If you write
Var arr = eval ('[' + d + ']');
$. InArray (3, arr)>-1 // true
});
Why? Hope you will know your friend and reply.
Jquery inarray () Functions
Jquery. inarray (value, array)
Determine the position of the first parameter in the array (-1 is returned if no value is found ).
Determine the index of the first parameter in the array (-1 if not found ).
Return Value
Jquery
Parameters
Value (any): used to search for existence in the array
Array (array): the array to be processed.
A friend asked a question today, as shown below:
The Code is as follows:
Var testarr = [{"a": "0" },{ "B": "1" },{ "c": "2"}]; alert ($. inarray ({"a": "0"}, testarr ));
This value always returns-1;
At first glance, I did not notice it, so I wrote a paragraph to show it to him.
The Code is as follows:
Var obj = {'M': '1'}; var arr = [obj, '1', 2]; alert ($. inarray (obj, arr ));
The returned value is normal.
Later I realized that the object is of the reference type.
You can use a short program to demonstrate the features of the reference type.
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;