Skip to content

Ilyas Kazi

Solution Architect, Laravel Developer, Passionate blogger, expressing to connect, help and build relationships

Category: Javascript

Return last word of string in JavaScript

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;
}

Continue reading “Return last word of string in JavaScript”

Author Ilyas KaziPosted on June 14, 2016Categories JavascriptTags String

Categories

  • General
  • Javascript
  • PHP
  • Technology

Recent Posts

  • Succeed with Math-Kindle Edition in 2 Parts from The Open University
  • 5 Free Online Technology courses from The Open University
  • A small halt at Roha Railway Station
  • Returning back from the daily boredoms
  • Return last word of string in JavaScript

Recent Comments

  • Ilyas Kazi on 5 Free Online Technology courses from The Open University
Ilyas Kazi Proudly powered by WordPress