从对象属性值中删除逗号 [英] Removing comma from an object property value

查看:62
本文介绍了从对象属性值中删除逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象,其中一对对象的值中包含逗号.我想为对象中的所有此类值删除此逗号,并返回修改后的对象.对象如下-

I have an object with one of the pairs having a value which has a comma in it. I want to remove this comma for all such values in the object and return the modified object. The object is as follows -

var obj = [
            {
            id: 1,
            Product1: "Table",
            Phone1: "9878987",
            Price:"21,000"},
        {
            id: 2,
            Product1: "Chair",
            Phone1: "9092345",
            Price:"23,000"},
        {
            id: 3,
            Product1: "Cupboard",
            Phone1: "9092345",
            Price:"90,000"}    
        ];

alert(JSON.stringify(obj)); 

我要删除价格值中的逗号(例如23,000 ==> 23000).该怎么办?

I want to remove comma in Price value(e.g- 23,000 ==> 23000). How can this be done?

推荐答案

您可以使用

You can use Array.prototype.forEach() to iterate over all your items and modify the item.Price:

var obj = [{id: 1,Product1: "Table",Phone1: "9878987",Price:"21,000"},{id: 2,Product1: "Chair",Phone1: "9092345",Price:"23,000"},{id: 3,Product1: "Cupboard",Phone1: "9092345",Price:"90,000"}];

obj.forEach(function(item) {
  item.Price = item.Price.replace(/,/, '');
});      

console.log(obj);

这篇关于从对象属性值中删除逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆