Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove first element from jQuery collection (shift() equivalent) [duplicate]

Tags:

arrays

jquery

In plain javascript, I can remove the first element of an array and store it in a variable like:

var rows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var firstRow = rows.shift();
// now firstRow contains the first element of the original rows array,
// and rows contains the remaining elements.

How do I do the same thing with a jQuery collection?

var $rows = $('#some-table').find('> tbody > tr');
// ?
// ?
like image 376
jbyrd Avatar asked Feb 14 '26 15:02

jbyrd


1 Answers

var rows = $('tr');
var first = rows.first();
var rest = rows.slice(1);

Reference:

  • .first()
  • .slice()
like image 135
Ouroborus Avatar answered Feb 16 '26 03:02

Ouroborus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!