将对象的值编号转换为字符串无法正常工作

时间:2019-09-19 01:39:44

标签: javascript

我有将数字转换为字符串的情况。在下面的功能中。我正在迭代对象并尝试更改plan_price的值类型。当我执行console.log()时它正在工作

    bestPlanArrange(bridals){
        let plans = [];
        bridals.filter(item => {
            item.plans.filter(plan => {
                plans.push(plan);
            });
        })
        let obj = {}
        let planArr = [];
        plans.filter(item => {
            item.plan_price.toString()
            console.log(item.plan_price) // doesn't listen the code above not working. 
            console.log(item.plan_price.toString()) // it's working like this.
            planArr.push(item) // I want to push after covert.
        })
        if (planArr[0] != null && plans[0].plan_price != null) {
            obj = planArr[0];
        }
        return obj;
    },

我在这里错过了什么还是做错了什么?

1 个答案:

答案 0 :(得分:4)

调用toString()不会更改该值。您必须将结果分配回变量:

item.plan_price = item.plan_price.toString()