This function returns last word of your string.
For example, your string = My lucky color will give you the result = color
function get_last_word(str, sep) { var last_word = ''; if (str != '') { sep = ( ! sep) ? '-' : sep; last_word = str.split(sep).splice(-1)[0]; } return last_word; }