Created
September 12, 2020 20:48
-
-
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.)
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
| /** | |
| * @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