JavaScript Package For Removing Last Element Of An Array. And It Also Return The Element.
npm install --save remove-last-element
<script src="https://rawgit.com/Prosen-Ghosh/remove-last-element/master/remove-last.js"></script>
<script src="https://cdn.rawgit.com/Prosen-Ghosh/remove-last-element/06708e6c/remove-last.js"></script>
const removeLast = require('remove-last-element');
let array = [1,2,3,4,"foo","baz",{},[]];
console.log(array);
//=> [ 1, 2, 3, 4, 'foo', 'baz', {}, [] ]
removeLast(array)
//=> []
console.log(array);
//=> [ 1, 2, 3, 4, 'foo', 'baz', {} ]
removeLast(array)
//=> {}
console.log(array);
//=> [ 1, 2, 3, 4, 'foo', 'baz' ]
removeLast(array)
//=> 'baz'
console.log(array);
//=> [ 1, 2, 3, 4, 'foo' ]
removeLast(array)
//=> 'foo'
console.log(array);
//=> [ 1, 2, 3, 4 ]
removeLast(array)
//=> 4
console.log(array);
//=> [ 1, 2, 3 ]
removeLast(array)
//=> 3
console.log(array);
//=> [ 1, 2 ]
removeLast(array)
//=> 2
console.log(array);
//=> [ 1 ]
removeLast(array)
//=> 1
console.log(array);
//=> []
removeLast(array)
//=> RangeError: Array Is Empty
removeLast([])
//=> RangeError: Array Is Empty
Prosen Ghosh prosenghosh25@gmail.com (https://bd.linkedin.com/in/prosen-ghosh-baba9aa8)
- MIT