我有将数字转换为字符串的情况。在下面的功能中。我正在迭代对象并尝试更改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;
},
我在这里错过了什么还是做错了什么?
答案 0 :(得分:4)
调用toString()
不会更改该值。您必须将结果分配回变量:
item.plan_price = item.plan_price.toString()