Created
September 14, 2020 05:35
-
-
Save luavixen/05081b4b844c660b562d6c3c75fb7879 to your computer and use it in GitHub Desktop.
Object.prototype.toString is a thing, so how about toArray?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toArray() { | |
var length = this.length; | |
if ( | |
typeof length === "number" | |
&& length === length | |
&& length > 0 | |
) { | |
var array = new Array(length); | |
for (var i = 0; i < length; i++) { | |
array[i] = this[i]; | |
} | |
return array; | |
} | |
return []; | |
} | |
Object.prototype.toArray = toArray; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment