fuzzy dunlop
fuzzy dunlop

Reputation: 477

Javascript File path fix

How do i convert the string;

var s='uploads\product\picture\20Duleek_Lime_Green1.jpg';

into

'uploads/product/picture/20Duleek_Lime_Green1.jpg';

The standard javascript function replace doesnt seem to work.

var s='uploads\product\picture\20Duleek_Lime_Green1.jpg';

strReplace = s.replace('\\', '//');

alert(strReplace);

Upvotes: 2

Views: 1985

Answers (2)

epascarello
epascarello

Reputation: 207501

There is no replaceAll in JavaScript, use a regular expression with a global flag.

var s='uploads\\product\\picture\\20Duleek_Lime_Green1.jpg';
var strReplace = s.replace(/\\/g, '/');
alert(strReplace);

Upvotes: 4

Naftali
Naftali

Reputation: 146302

There is no such function in javascript called replaceAll

You can use regex with replace() to achieve what you want to do.

Upvotes: 0

Related Questions