var last = names.split(/\s+/).pop();
Explanation: .splitsplits the string at the specified delimiter and returns an array. /\s+/is a regular expression for "one or more spaces" (space, tab, newline, etc.). .pop()takes the last value from the array returned .split.
source
share