user1749062
user1749062

Reputation: 43

Splitting of filename in javascript

I want to split the filename and get the last path of the string in javascript.

For example the path is D://Smita//GMAP//Images//images.jpg , but according to my requirement it should be Images/images.jpg How to acheive this using javascript?

Upvotes: 0

Views: 185

Answers (1)

Fabrício Matté
Fabrício Matté

Reputation: 70169

split, slice and join:

var path = 'D://Smita//GMAP//Images//images.jpg'.split('//').slice(-2).join('/');
//path is "Images/images.jpg"

For a Google Maps info window you should be able to throw it as the src of an img element:

content: '<img src="'+path+'">'

See related How to add an image to InfoWindow of marker in google maps v3?

Upvotes: 2

Related Questions