#12003 closed bug (invalid)
jQuery.inArray() returns -1 for value that is in array if it is the only element in array
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
var a = new Array(4);
$.inArray(4, a) returns -1.
This should return 0, shouldn't it?
Change History (4)
comment:1 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 Changed 11 years ago by
@reporter
var a = [4]; console.log($.inArray(4, a)); 0
var a = [1,4]; console.log($.inArray(4, a)); 1
comment:3 Changed 11 years ago by
Yes, here you've used a literal. In your original example, you used the new Array()
constructor, which creates arrays like...
var a = new Array(1); a.length; // 1 a[0]; // undefined
var a = new Array(1, 2, 3); a.length; // 3 a[0]; // 1
The Array constructor creates an array of N length when passed a single numeric argument
Note: See
TracTickets for help on using
tickets.
new Array(4)
create[,,,]
not[4]
.