Get Last Array Element - Node.js Array

Node.js examples for Array:Last Element

Description

Get Last Array Element

Demo Code


function getLastArrayElement ( array )
{
  if ( array.length === 0 )
    throw 'Error: trying to get last element of an empty array';

  return array[ array.length - 1 ];
}

Related Tutorials