Ruphaa's Notes

How to get the last word in a string in JS?

js

var word = str.split("-").pop();

OR;

var last = str.substring(str.lastIndexOf("-") + 1);

OR;

var data = "Welcome to Stack Overflow";
console.log(data.split(" ").splice(-1));