Home > Article > Web Front-end > A brief discussion on the object traversal .eq().first().last().slice() method in jQuery_jquery
eq(index): Extract the element with index index in the collection.
first(): Returns the first element in the collection.
.last(): The last element in the guard collection.
.slice(start[,end]): Returns the elements of the given interval in the collection.
first() and last() call eq(), eq() is implemented through slice(), and slice() is implemented through
.pushStack() implementation.
Related source code
Line 285: The usage is very strange, using a " " to convert i, which may be a string, into a numerical value.
300~301: First use the array method slice() to obtain a subset of the specified range from the current jQuery object,
Use the pushStack() method to convert the subset into a jQuery object, while retaining a reference to the current jQuery object through the attribute prevObject.
The above is the entire content of learning .eq(), .first(), .last(), .slice() based on the jQuery source code. Do you guys understand them?