Answer the question
In order to leave comments, you need to log in
How to remove the last word in a line?
I have a string
I want to get from it
I tried to do so.
var names = 'red/blue\green\yellow/brown'
var names = 'red/blue/green/yellow/'
var names = 'red/blue\green\yellow/brown'
var nameList = names.split('/');
console.log(nameList )
nameList.pop()
console.log(nameList )
var names2 = nameList.join('/')
console.log(names2 )
var str = 'red/blue\green\yellow/brown'
var lastIndex = str.lastIndexOf("/");
str = str.substring(0, lastIndex);
console.log(str)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question