Created
November 30, 2015 12:37
-
-
Save enricodeleo/60ed932644966041aeac to your computer and use it in GitHub Desktop.
Extend an Array appending elements of another Array in Javascript
This file contains 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
// Shorthand function | |
Array.prototype.append = function(array) { | |
this.push.apply(this, array) | |
} | |
// Example | |
var a = [1,2]; | |
var b = [3,4]; | |
a.append(b); // 'a' bacames [ 1, 2, 3, 4 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment