-4

Guys i have many links:

"img/dasda/ja.png", "../img/no.png", "wild/rpm/gulp/in.png",

How in js change sting to last "/"? To get just the name of image?

1
  • What research have you done and what have you tried? Commented Feb 19, 2017 at 10:55

2 Answers 2

0

var url = "img/dasda/ja.png";

var idx = url.lastIndexOf('/');
console.log(url.substring(idx + 1));

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, thats work
0

You could use Array#match together with RegExp.

var links = ["img/dasda/ja.png", "../img/no.png", "wild/rpm/gulp/in.png"];

links.forEach(v => console.log(v.match(/(?!\/)\w+(?=\.)/g)[0]));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.