0

I'm working on a basic website using NextJS, my code is like this

products: [
 {
   brand: 'example',
   price: 10000,
 },
...
],

How do I change the 10000 to 10,000.

gem173
  • 37
  • 8

1 Answers1

3

You can use toLocaleString() to format the number with commas like this:

var a = 10000000;
console.log(a.toLocaleString())

var obj = {products: [
 {
   brand: 'example',
   price: 10000,
 }
]
}

obj.products[0].price = obj.products[0].price.toLocaleString()

console.log(obj)
JaivBhup
  • 792
  • 4
  • 7