Using js remove comma from number from existing data
Use Array.prototype.map()
and String.prototype.replace()
to modify the property Total
:
var data = [{"Date": "2018-03-20", "Total": "10,459"},{"Date": "2018-03-21", "Total": "11,947"},{"Date": "2018-03-22", "Total": "12,932",}];
data = data.map(i => { i.Total = i.Total.replace(/,/g,''); return i;});console.log(data);
How to remove comma from number which comes dynamically in .tpl file
var a='1,125';
a=a.replace(/\,/g,''); // 1125, but a string, so convert it to number
a=parseInt(a,10);
Hope it helps.
remove comma separation from the specific number from JS
You can simplify the regular expression:
num.replace(/,/g, '')
How to remove comma if there is no next value
might not be the most elegant solution but you could add the comma only if defined using the ternary operator
const obj = {
address1: "15th street",
state: "NY",
zip_code: 12345
}
obj.address1 = obj.address1 + ', ' + (obj.city ? obj.city + ', ' : '') + (obj.state ? obj.state + ', ' : '') + obj.zip_code;
console.log(obj.address1)
Take commas from input field, remove them, and store value with remove comma in different value
You can use replace()
function to remove certain string from string.
$("#first").keyup(function(event) {
// skip for arrow keys if(event.which >= 37 && event.which <= 40) return;
// format number $(this).val(function(index, value) { return value .replace(/\D/g, "") .replace(/\B(?=(\d{3})+(?!\d))/g, ",") ; }); var firstValue = Number($('#first').val().replace(/,/g,'')); console.log(firstValue);});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><input id='first' placeholder="0" type="text" maxlength="10"autocomplete="off"/>
Related Topics
How to Update Component State on Redux State Change
Document.Queryselector Always Returns Null
How to Translate the Following Jquery Code to React
How to Put a Variable in an Src Attribute
How to Remove a Parameter from a Url
Detect If Page Is Load from Back Button
Disabled Button Onclick Event Fires
How to Do Validation for 10 Digit Mobile Number Using Jquery
Why Is It a Bad Practice to Return Generated HTML Instead of Json or Is It
Hosting Your Own JavaScript Scripts Files (Other Than Jquery) on Fast Free Cdns Like Google
Reactjs Dynamic Drop Down Populated With Map Function
Detect Click into Iframe Using JavaScript
Trying to Load a Script File from My Node Server - Get 404
When Click on Menu, It Opens, When Click Again It Close
Modifying a Query String Without Reloading the Page
Prevent Bootstrap Modal Window from Closing on Form Submission