Answer the question
In order to leave comments, you need to log in
How to pull an object from an array?
There is an array products, in which product.price, I need to pull it out from there in order to convert it to a monetary format. How can it be pulled out?
I did this, but it does not work, apparently not correctly)
computed:{
priceProduct(){
var prc = this.products.reduce((product) => parseFloat(product.price), 0);
return parseFloat(prc).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1 ").replace('.', ',');
},
}
Answer the question
In order to leave comments, you need to log in
Instead of a computed property, make a filter:
filters: {
price: val => val.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1 ").replace('.', ','),
},
td {{ product.price | price }}
price: val => val.toLocaleString('ru', {
style: 'currency',
currency: 'RUB',
}),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question