0

Trying to update the values in a map in javascript. Below is how my map looks like.

Data in Map :[{…}]

[{
  accId: "001",
  lineOfBusiness: "Protection",
  name: "Ins",
  plannedValue: 1200.18,
  SellOutValue: 4115.85,
  productGroup: "INS",
  sesnId: "a2s",
  subGroups: [{
    accountId: "001",
    brandName: "INS",
    isLocked: true,
    lineOfBusiness: "Ction",
    name: "Ins",
    portfolioId: "a34",
    productGroup: "IDES",
    recordId: "006",
    seasonId: "a2s",
    territoryId: "0MI",
    unitOfMeasurement: "MXN"
  }]
}]

Here i am trying to update the map values plannedValue and SellOutValue with the updated values in a new map. when i am executing the below code i am getting the error

set is not a function.

//Cloning the map and formatting the values
let map1 = {};
for(var i in incoming){
    map1[i] = incoming[i]
    map1[i].set('plannedValue',map1[i].plannedValue.toLocaleString())
    map1[i].set('SellOutValue',map1[i].SellOutValue.toLocaleString())
}
console.log(map1);

can someone please help me on this

pilchard
  • 12,414
  • 5
  • 11
  • 23
user5558
  • 25
  • 4

1 Answers1

0

map[i] is an object (an element of the incoming Map), not a Map. So use ordinary property access.

map[i].plannedValue = map1[i].plannedValue.toLocaleString();
map[i]. SellOutValue = map1[i].SellOutValue.toLocaleString();

Note that you're not making clones of the objects in the Map, so this will modify the original objects as well.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I don't want to change the structure even. My main aim is to update the plannedValue and SellOutValue with the formatted values in the map. Can you please help me with this, how to update the values with the formatted values in the same map. thanks in advance, – user5558 Jan 25 '21 at 17:28
  • [how to clone an object](https://stackoverflow.com/questions/728360/how-do-i-correctly-clone-a-javascript-object) – Barmar Jan 25 '21 at 17:30