Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get last string after / in javascript

// Regex
var result = /[^/]*$/.exec("foo/bar/test.html")[0];

// Using lastIndexOf and substring
var str = "foo/bar/test.html";
var n = str.lastIndexOf('/');
var result = str.substring(n + 1);

// Using Array#split
var parts = "foo/bar/test.html".split("/");
var result = parts[parts.length - 1]; // Or parts.pop();
Comment

get last word in string js

function test(words) {
    var n = words.split(" ");
    return n[n.length - 1];
}
Comment

how to get last string in javascript

'abc'.slice(-2);
Comment

get last character of string javascript

str.charAt(str.length-1) 
Comment

javascript get last word in string

// strips all punctuation and returns the last word of a string
// hyphens (-) aren't stripped, add the hyphen to the regex to strip it as well
function lastWord(words) {
    let n = words.replace(/[[]?.,/#!$%^&*;:{}=|_~()]/g, "").split(" ");
    return n[n.length - 1];
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript object remove empty properties 
Javascript :: javascript get query parameter 
Javascript :: adding numbers in an array javascript 
Javascript :: convert file to blob javascript 
Javascript :: js iterate match indexes 
Javascript :: how to make a button execute a javascript function 
Javascript :: faker.js avatar 
Javascript :: object to array javascript 
Javascript :: can we add jquery in chrome extension js code 
Javascript :: lodash sumby 
Javascript :: How to get input file using js 
Javascript :: get file extension node 
Javascript :: generate id js 
Javascript :: react native tab.screen hide title 
Javascript :: javascript credit card validation 
Javascript :: javascript get array min and max 
Javascript :: rounding up a number so that it is divisible by 5 javascript 
Javascript :: is node js faster than python 
Javascript :: get url react 
Javascript :: open new window chrome extension 
Javascript :: is var is not blank then display value in javascript 
Javascript :: jquery make new variable with dynamic name 
Javascript :: remove comma from number javascript 
Javascript :: promise catch 
Javascript :: how to change text color in react 
Javascript :: using bootstrap in react 
Javascript :: formarray patchvalue at index 
Javascript :: expressjs 
Javascript :: create component with module and routing in angular 8 
Javascript :: mongoose schema cast decimals 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =