-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?

Eugeny
  • 9

2 Answers2

0

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

var idx = url.lastIndexOf('/');
console.log(url.substring(idx + 1));
rasmeister
  • 1,986
  • 1
  • 13
  • 19
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]));
kind user
  • 40,029
  • 7
  • 67
  • 77