Introduction to the Inarray method of jquery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.