Skip to main content

Bug Tracker

Side navigation

#7108 closed bug (invalid)

Opened October 01, 2010 05:22PM UTC

Closed October 01, 2010 07:29PM UTC

Last modified October 01, 2010 07:32PM UTC

slice() end count error

Reported by: pjobson Owned by:
Priority: undecided Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

This is kind of particularity I found when working with negative indexes and slice. I'm not 100% sure if it is a bug or expected behavior.

I'll just get onto the example:























<script type="text/javascript">

var x = [-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];

$.each(x,function(a,b) {






When variable b gets to -1, nothing is returned, though I expect what should be returned is the li at the 19th position.

The final two console.log examples show it failing then succeeding, the main concern is if the second variable must be something (not null or ''), it makes it kind of a pain in the butt to do dynamic list indexing, as I would have to do some kludge like the following:

var x;

if (b==-1) {

x = $('li').slice(b);

} else {

x = $('li').slice(b,b+1);


Attachments (0)
Change History (2)

Changed October 01, 2010 07:29PM UTC by snover comment:1

resolution: → invalid
status: newclosed

Thanks for the report, but this is not a jQuery bug. jQuery simply inherits the browser’s native Array.slice functionality. You will need to use a conditional as you suggested at the end of the bug description. test case

Changed October 01, 2010 07:32PM UTC by snover comment:2