1

Here is my issue hope that someone can help me:

//Declartions

var DBName = somthing; // changed dynamically 
var lastPiece;

I have this string:

"../PeopleImages/GGP/Person_3281.jpg"

I want to grab "Person_3281.jpg" piece in the string save it into a variable lastPiece = Person_3281.jpg; (The last piece is been change dynamically).

and after that combined it to another string for example:

var address = "https://www.google.com/gs/companyCode="+ DBName + lastPiece ;

how can I do it in Javascript??

1

2 Answers 2

1
var string = "../PeopleImages/GGP/Person_3281.jpg";
var arrFromString = string.split('/');

var lastPiece = arrFromString[arrFromString.length -1];
Sign up to request clarification or add additional context in comments.

Comments

0

You can achieve this with a pretty simple regex:

var originalstring = "../PeopleImages/GGP/Person_3281.jpg";
var lastpiece = /[^/]*$/.exec(originalstring)[0];

reference

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.