split last javascript code example
Example 1: javascript split get last element
a = "hello.dear.friends"
a.split(".").pop()
> "friends"
Example 2: js split last occurence
var lastIndex = src.lastIndexOf('.');
// Add the string before the last .
// Return updated string, this will update the src attribute value
return src.substr(0, lastIndex) + '-fx' + src.substr(lastIndex);
Example 3: split and get last
Use rev command altogether with cut command as follows:
echo "a1 a2 a3 a4 a5" | rev | cut -d ' ' -f '1' | rev