Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace function of JavaScript don't work

Tags:

javascript

I have next code in javascript:

csvReport.name = "My New Report";
$scope.filename = csvReport.name.replace(" ", "_");

But I get $scope.filename = My_New Report. Not all spaces replacing.

What is it?

like image 462
IFrizy Avatar asked Dec 04 '22 08:12

IFrizy


1 Answers

.replace will always replace the first occurence except if you use regular expression like that :

csvReport.name.replace(/ /g, "_");
like image 68
Karl-André Gagnon Avatar answered Dec 17 '22 18:12

Karl-André Gagnon