Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing comma for value with Javascript

Tags:

javascript

thanks for looking my questions, I can't find the way to remove the comma with javascript. So I have problem at removing comma from page with java-script, Adding Comma for output is fine i guess, but for removing comma for value, the function is not working for me.

The source code is : http://jsfiddle.net/Q5CwM/2/

Please let me know, thanks again.

like image 784
XML guy Avatar asked Oct 20 '11 22:10

XML guy


People also ask

How to remove the commas from a string in JavaScript?

To remove the commas from a string, we can use the replace () method in JavaScript. In the example above, we have passed two arguments to the replace () method, the first one is regular expression /,/g, the second one is an empty string "". so it replaces all instances of a comma with an empty string.

How do I remove the comma from an international date?

Use the international date local via format. This cleans up any bad inputs, if there is one it returns a string of NaN you can check for. There's no way currently of removing commas as part of the locale (as of 10/12/19), so you can use a regex command to remove commas using replace.

How to split the sentences by comma and remove surrounding spaces-JavaScript?

Split the sentences by comma and remove surrounding spaces - JavaScript? To split the sentences by comma, use split (). For removing surrounding spaces, use trim (). node fileName.js.

How do you match all commas in a string in Python?

The first parameter we passed to the String.replace method is a regular expression that matches all the commas in the string. We use the g (global) flag at the end of the regex, because we want to match all commas and not just the first occurrence in the string.


Video Answer


1 Answers

I have no idea what your code is trying to do overall, but you can fix this function that removes commas:

function checkNumeric(objName) {
    var lstLetters = objName;
    var lstReplace = lstLetters.replace(/\,/g,'');
}

by changing it to this:

function removeCommas(str) {
    return(str.replace(/,/g,''));
}

You weren't returning the changed string from the function and I changed the name of the function and parameters to represent what it does.

str.replace returns the changed string. It does not change the string you started with so in order to do something with the result of the replacement, you have to either return that from the function or assign it to some other string. As you had it, nothing was happening with the replaced string so the function did nothing.

like image 196
jfriend00 Avatar answered Sep 28 '22 03:09

jfriend00