Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Array multiple with prototype
Array.prototype.multiply = function(){
const le = this.length;
for(let i=0; i < le; i++){
this[i+le] = this[i]*this[i];
console.log(this)
}
};
const a = [1, 2, 3, 4, 5];
a.multiply();
console.log(a); //[1, 2, 3, 4, 5, 1, 4, 9, 16, 25]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment