Javascript quirks, tips, et cetera

— 1 minute read

Slice on array-like objects permalink

MDN: Array.prototype.slice for Array-like objects

function incorrect() {
    return arguments.slice(1); //throws and error
}

function error() {
    return Array.prototype.slice(arguments, 1);
}

The incorrect function does not work because arguments is not an array - it is an Array-like object. However, we can still use the slice method from Array's prototype.