🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › slice
Array.prototype.slice() - JavaScript | MDN
The slice() method of Array instances returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
🌐
W3Schools
w3schools.com › jsref › jsref_slice_array.asp
JavaScript Array slice() Method
The slice() method returns selected elements in a new array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › slice
String.prototype.slice() - JavaScript | MDN
The slice() method of String values extracts a section of this string and returns it as a new string, without modifying the original string.
🌐
Codecademy
codecademy.com › docs › javascript › arrays › .slice()
JavaScript | Arrays | .slice() | Codecademy
May 22, 2025 - The .slice() method in JavaScript returns a partial copy of an array, otherwise known as a shallow copy, without altering the original array.
🌐
Built In
builtin.com › software-engineering-perspectives › array-slice-javascript
3 Ways to Use Array Slice in JavaScript | Built In
Summary: Learn three ways to use JavaScript’s slice() method: to copy an array, to get the first N elements in an array and to remove an element at a specific index — all without modifying the original array. The slice() method returns a shallow copy based on optional start and end...
🌐
Mimo
mimo.org › glossary › javascript › array-slice
JavaScript Array slice() Method: Syntax, Usage, and Examples
The slice() method returns a shallow copy of a portion of an array into a new array object, selected from a start index to an end index (end not included). The original array remains unchanged. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, ...
🌐
Medium
medium.com › swlh › the-javascript-slice-cheat-sheet-3746c9326bbf
The JavaScript Slice Cheat Sheet
November 13, 2020 - ... “The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array…"
🌐
Refine
refine.dev › home › blog › tutorials › how to use javascript slice method
How to Use JavaScript Slice Method | Refine
November 4, 2024 - Array.prototype.slice is a JS Array method that is used to extract a contiguous subarray or "slice" from an existing array. JavaScript slice can take two arguments: the start and the end indicator of the slice -- both of which are optional.
🌐
CoderPad
coderpad.io › blog › development › 4-ways-to-use-javascript-slice-method
4 Ways to Use JavaScript .slice() Method and How to Do Each - CoderPad
June 7, 2023 - ℹ️ Before getting started, we assume that you understand how functions work in JavaScript. If not, check out the JavaScript functions guide to learn more. Put simply, .slice() returns a portion of an array.
Find elsewhere
🌐
daily.dev
daily.dev › home › blog › get into tech › js array slice: a beginner's guide
JS Array Slice: A Beginner's Guide
December 22, 2025 - Learn how to use the slice() method in JavaScript to extract parts of an array without altering the original. Discover its syntax, differences from other methods, practical examples, and best practices.
🌐
Mimo
mimo.org › glossary › javascript › string-slice
JavaScript String slice() Method: Syntax, Usage, and Examples
Learn how to use the JavaScript slice() method to extract parts of a string for trimming, parsing, formatting, and building clean, immutable text logic.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer › slice
ArrayBuffer.prototype.slice() - JavaScript | MDN
The slice() method of ArrayBuffer instances returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from start, inclusive, up to end, exclusive. If either start or end is negative, it refers to an index from the end of the array, as opposed to from the beginning.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-slice-method
JavaScript Array slice() Method - GeeksforGeeks
December 27, 2017 - The slice() method allows you to copy a specific portion of an array. It creates a new array containing only the selected elements. It takes a start index and an end index to decide which elements to extract.
🌐
Programiz
programiz.com › javascript › library › array › slice
JavaScript Array slice()
const languages = ["JavaScript", "Python", "C", "C++", "Java"]; // slicing the array from start to second-to-last · let new_arr = languages.slice(0, -1); console.log(new_arr); // [ 'JavaScript', 'Python', 'C', 'C++' ] // slicing the array from third-to-last
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › TypedArray › slice
TypedArray.prototype.slice() - JavaScript | MDN
The slice() method of TypedArray instances returns a copy of a portion of a typed array into a new typed array object selected from start to end (end not included) where start and end represent the index of items in that typed array. The original typed array will not be modified.
🌐
jQuery
api.jquery.com › slice
.slice() | jQuery API Documentation
Given a jQuery object that represents a set of DOM elements, the .slice() method constructs a new jQuery object containing a subset of the elements specified by the start and, optionally, end argument.
Top answer
1 of 9
190

What's happening here is that you call slice() as if it was a function of NodeList using call(). What slice() does in this case is create an empty array, then iterate through the object it's running on (originally an array, now a NodeList) and keep appending the elements of that object to the empty array it created, which is eventually returned. Here's an article on this.

EDIT:

So it starts with an empty array [], then slice is used to convert the result of call to a new array yeah?

That's not right. [].slice returns a function object. A function object has a function call() which calls the function assigning the first parameter of the call() to this; in other words, making the function think that it's being called from the parameter (the NodeList returned by document.querySelectorAll('a')) rather than from an array.

2 of 9
160

In JavaScript, methods of an object can be bound to another object at runtime. In short, javascript allows an object to "borrow" the method of another object:

object1 = {
    name: 'Frank',
    greet() {
        alert(`Hello ${this.name}`);
    }
};

object2 = {
    name: 'Andy'
};

// Note that object2 has no greet method,
// but we may "borrow" from object1:

object1.greet.call(object2); // Will show an alert with 'Hello Andy'

The call and apply methods of function objects (in JavaScript, functions are objects as well) allows you to do this. So, in your code you could say that the NodeList is borrowing an array's slice method. .slice() returns another array as its result, which will become the "converted" array that you can then use.