Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript the last word of a string

// Get the last word of a string.

let str = "What I hate most in the world is fanaticism.";

// 1) The slice() method: without Considering the punctuation marks
str.slice(str.lastIndexOf(' ')); // => 'fanaticism.'

// 2) the spit() method():
let arr = str.split(' ');
arr[arr.length - 1]; // => 'fanaticism.'


// Considering the punctuation marks at the end of the string
str.match(/(w+)W*$/)[1]; // => 'fanaticism'
Comment

Js last word in a string

String test =  "This is a sentence";
String lastWord = test.substring(test.lastIndexOf(" ")+1);
Comment

javascript get last n characters of string

'abc'.slice(-1); // c
Comment

how to get last string in javascript

'abc'.slice(-2);
Comment

get last letter of string javascript

// Get last n characters from string
var name = 'Shareek';
var new_str = name.substr(-5); // new_str = 'areek'
Comment

get last character of string javascript

str.charAt(str.length-1) 
Comment

javascript last character of a string

const myString = "linto.yahoo.com.";
const stringLength = myString.length; // this will be 16
console.log('lastChar: ', myString.charAt(stringLength - 1)); // this will be the string
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: js object get type 
Javascript :: vuejs get the url params withour router 
Javascript :: select by style in jquery 
Javascript :: node array 
Javascript :: JavaScript function that generates all combinations of a string. 
Javascript :: sort by string react 
Javascript :: jquery check if class exists 
Javascript :: dictionary in javascript 
Javascript :: opencv rtsp stream python 
Javascript :: is object 
Javascript :: check if url is http or https javascript 
Javascript :: Cannot resolve taglib with uri http://java.sun.com/jsp/jstl/core 
Javascript :: replace space with hyphen/dash javascript 
Javascript :: route component with props 
Javascript :: how to instance in a node with code godot 
Javascript :: angular refresh token 
Javascript :: react scrollTop smooth 
Javascript :: axios cancel previous request 
Javascript :: convert number to word js 
Javascript :: get object key name in js 
Javascript :: open xcode shorthand react native 
Javascript :: convert days into year, Month, days 
Javascript :: localstorage javascript array 
Javascript :: javascript check if null 
Javascript :: get data from formdata 
Javascript :: javascript function loop through array 
Javascript :: create function replace all n javescript 
Javascript :: javascript regex generator 
Javascript :: onselect javascript 
Javascript :: chart.js label word wrap 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =