Set Last Array Element - Node.js Array

Node.js examples for Array:Last Element

Description

Set Last Array Element

Demo Code


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

  array[ array.length - 1 ] = val;
}

Related Tutorials