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];
}'abc'.slice(-2);function test(words) {
var n = words.indexOf(" ");
var res = words.substring(n+1,-1);
return res;
}
Also in JavaScript:
- angular form validation
- rest api node js with mysql
- node-fetch auth basic
- jquery form data
- how to lazyload angular
- javascript max characters string function
- check if 2 strings matches js
- ejemplo async await javascript
- reactjs Module not found: Can't resolve 'styled-components
- javascript remove duplicates from array
- how to add class to button in javascript
- ajax error
- javascrip reverse text
- set dynamic route in link react js
- making promises in js
- vue dynamic create watch
- discord.js find word inside comment
- javascript sendredirect
- vue for loop
- chrome extension dynamically add javascript
- javascript find smallest number in an array
- history.pushstate
- vue store access state in actions
- javascript redirect to homepage