Skip to content

Instantly share code, notes, and snippets.

@Anenth
Created November 14, 2018 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anenth/3d967c7130108c82377f524f0b61567d to your computer and use it in GitHub Desktop.
Save Anenth/3d967c7130108c82377f524f0b61567d to your computer and use it in GitHub Desktop.
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