last

Return the last n UTF-16 code units of a string.

Usage

var last = require( '@stdlib/string/base/last' );

last( str, n )

Returns the last n UTF-16 code units of a string.

var s = last( 'hello world', 1 );
// returns 'd'

s = last( 'this is stdlib', 1 );
// returns 'b'

s = last( 'foo', 2 );
// returns 'oo'

s = last( 'foo bar', 10 );
// returns 'foo bar'

Examples

var last = require( '@stdlib/string/base/last' );

var str = last( 'elections', 1 );
// returns 's'

str = last( 'JavaScript', 1 );
// returns 't'

str = last( 'good night', 5 );
// returns 'night'
Did you find this page helpful?