Skip to content

Instantly share code, notes, and snippets.

@Matsukii
Created September 12, 2020 20:48
Show Gist options
  • Select an option

  • Save Matsukii/ca4601fe7725e4098cd725723f7501ae to your computer and use it in GitHub Desktop.

Select an option

Save Matsukii/ca4601fe7725e4098cd725723f7501ae to your computer and use it in GitHub Desktop.
A array prototype function to get/set the last item of an array (minified ver.)
/**
* @description get last item of an array or set the value of the last item
* @author Matsukii
* @license MIT
* @returns last item of an array
*/
Array.prototype.lastItem = function(set=undefined){let i=this.length-1;if(set){if(typeof set==="object"){this[i]={...this.lastItem(),...set}}else{this[i]=set}}return this[i]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment