Reputation: 670
I have situation about converting number to string. In the function below. I am iterating the objects and trying to change value type of plan_price
. it's working when I do 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;
},
Do I missing something or doing something wrong here?
Upvotes: 0
Views: 806
Reputation: 97172
Calling toString()
doesn't change the value in place. You have to assign the result back to a variable:
item.plan_price = item.plan_price.toString()
Upvotes: 4