Get part of string into variable

javascript, string, variables

Solution

var last = names.split(/\s+/).pop(); // "Mark"

Explanation: `.split` splits a string on a given separator and returns an array. `/\s+/` is a regular expression for "one or more whitespaces" (space, tab, newline, etc). `.pop()` grabs the last value from the array that `.split` returns.

Problem

i need to get part of string into variable. (note, i will always use exactly 4 names) ``` var names = "Andrew Peter Bob Mark" ``` I need to get the last one to ``` var last = "Mark" ``` Thanks for help in advance

Original source