-1

i want to update a value in a array of object in javascript.

export var headingLeistenbelegung = [
  [ {value: 'Projektnummer: ', style: styles.headerDarkBold},
    {value: '121466', style: styles.headerDark},
    {value: 'Projektbezeichnung: ', style: styles.headerDarkBold},
    {value: 'adsadköald', style: styles.headerDark},
  ],
  [
  ],
  [ {value: 'Server ID: ', style: styles.headerDarkBold},
    {value: '3', style: styles.headerDark},
    {value: 'Serverbezeichnung: ', style: styles.headerDarkBold},
    {value: 'ANlage dies und das', style: styles.headerDark},
  ],
  [
  ],
  [ {value: 'Bucht: ', style: styles.headerDarkBold},
    {value: 'X3', style: styles.headerDark},
    {value: 'Leiste: ', style: styles.headerDarkBold},
    {value: 'leistenNummer', style: styles.headerDark},
  ],
  [
  ],
];



.....

  for(var k = 0; k<5; k++){
    log("Avorher")
    log(excelData.headingLeistenbelegung)

    excelData.headingLeistenbelegung[4][3].value = k.toString()

    log("Anachher1")
    log(excelData.headingLeistenbelegung[4][3].value)

    log("Anachher2")
    log(excelData.headingLeistenbelegung)
  }


the first log shows me the value of 4... why? I tried already to do an local copy of headingLeistenbelegung, but still the same.

i need this to add the heading to an Excelsheet later

Michael Mitch
  • 403
  • 2
  • 7
  • 17
  • Probably because `excelData.headingLeistenbelegung` has a value of 4. I'm just guessing, since you haven't show the content of `excelData`. – some Jan 25 '20 at 20:18
  • export var headingLeistenbelegung is in excelData..and the default value is 'leistenNummer' – Michael Mitch Jan 25 '20 at 20:20
  • you're running a loop, but you're assigning to `excelData.headingLeistenbelegung[4][3]` every time, so first you set it to 0, then it loops and you overwrite it with 1, then 2, then 3, then 4 and the loops stops. Not sure what you're trying to accomplish here – chiliNUT Jan 25 '20 at 20:34
  • yes.. but my log shout show me first "1" then "2" ...And i see immediately in the first log "4" and also in the 3 next logs – Michael Mitch Jan 25 '20 at 22:17

1 Answers1

0

ok i found something similar

console.log() shows the changed value of a variable before the value actually changes

this

console.log(JSON.parse(JSON.stringify(excelData.headingLeistenbelegung)))

helped me

Michael Mitch
  • 403
  • 2
  • 7
  • 17