Node.js examples for Array:Last Element
Set Last Array Element
function setLastArrayElement( array, val ) { if ( array.length === 0 ) throw 'Error: trying to get last element of an empty array'; array[ array.length - 1 ] = val; }