Modify ↓
Ticket #12003 (closed bug: invalid)
jQuery.inArray() returns -1 for value that is in array if it is the only element in array
| Reported by: | vic.emond@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
var a = new Array(4);
$.inArray(4, a) returns -1.
This should return 0, shouldn't it?
Change History
comment:1 Changed 11 months ago by scott.gonzalez
- Status changed from new to closed
- Resolution set to invalid
comment:3 Changed 11 months ago by rwaldron
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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

new Array(4) create [,,,] not [4].