Update the value within an object Array using a for loop

In JavaScript, I am looking to update a value in an array of objects.

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)
}


Upon logging the value of 4, it seems to return something unexpected. I have attempted creating a local copy of headingLeistenbelegung, but encountered the same issue. This update is essential for integrating the heading into an Excel sheet later on.

Answer №1

After some searching, I came across something similar.

I found a solution to the issue of console.log() displaying the changed value before it actually changes

Here is the code snippet that ultimately helped me:

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

I hope this can assist others facing a similar problem!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve ALL information from a third-party API request with a limit of 1000 calls

Challenge: Implementation of a third-party API call using Node.JS. The API link restricts the number of users per call to 1000, with an option to retrieve the next set by passing parameters in the URL (?firstResult=1001&maxResults=1000&orderBy=NAME ...

Maximizing the potential of .delegate in combination with .closest

$('.inputRadio').parent().click(function (e) { //implement delegate method here }); Looking for assistance on how to integrate the delegate method in the provided function. Any suggestions? ...

Navigating from an error page to the homepage with Next.JS 13: A quick and easy guide

I'm currently working on implementing a feature that allows users to easily go back to the main page from an error page within the app folder. Specifically, in my weather app project, if a user enters an incorrect city, they should have the option to ...

Taking out the modal element from the document object model, causing the animation

I am currently working on a project using Next.js, Typescript, and Tailwind CSS. Within this project, I have implemented a modal component with some animations. However, I encountered an issue where the modal does not get removed from the DOM when closed, ...

Using Angular and TypeScript: A guide to binding an ngModel to a variable key within an object

I have an object called WeeklyDriver with various keys. My goal is to iterate over an array of objects containing WeeklyDriver instances (referred to as drivers in my code), and then loop through a specific set of keys belonging to the WeeklyDriver object: ...

What steps are involved in testing an ErrorHandler in express.js?

I am attempting to run a fail case test for this TypeScript function using Sinon, however, I am unsure how to proceed. Can anyone provide assistance? public async findById(id: number): Promise<UserModel> { const user = await this._userModel.fi ...

Using JavaScript to halt the playback of HTML5 video in 'injected' HTML code

Although I know there have been similar issues resolved here before, none of the suggested solutions seem to work for me. Let me start by explaining my problem. I have a landing page located here: On the portfolio section of the landing page, I hav ...

Is it possible to use Javascript to read a text file?

Does anyone have experience reading text files from outside a mobile app built with XDK Intel? I attempted to use the following code, but unfortunately it's not yielding the desired outcome. function readFile (filepath){ var txtFile = "C:\tes ...

The useEffect alert is triggered before the component is re-rendered

Can someone help me understand why the HP in the code below is displayed as "1" when the alert is thrown, and only set to "0" after I confirm the alert? Shouldn't the component be rerendered before the alert is thrown so that it has already been displ ...

Guide: Ensuring the validity of an object retrieved from a database with Nest.js class-validator

When activating a user, I need to ensure that certain optional data in the database is not empty by using class-validator dto. So far, my controller level validations for body, query, and all other aspects have been successful. The DTO file contains vali ...

Execute functions in a random order

My array contains a series of functions and is structured as shown below: var all_questions = [ show_question(1, 1), show_question(2, 1), show_question(3, 1), ]; I'm interested in executing those functions within the array in a random or ...

Steps to halt webkit animation within a div located inside a circle:

I have a series of nested circle divs, and I want to give them a pulse animation. The issue is that the text container is within one of these circles, causing the animation to apply to the text as well. I am unable to move the text container due to potenti ...

How can I create a box-shaped outline using Three.js?

As someone new to threejs, I have been trying to figure out how to render a transparent box around a symbol in my canvas. The box should only display a border and the width of this border should be customizable. Currently, I am using wireframe to create a ...

Ordering two arrays in a for loop

I have two arrays to manage, one for numbers and the other for names. const number = ['91xxxx','1xxxx','92xxxx'] const name = ['Abhi','Arun','Aaron'] The goal is to pair each number with a corres ...

Angular JS and TypeScript - Issue: ng:areq Invalid Argument "Argument 'XXXXXX' is not a function, received undefined"

Encountering a specific error mentioned in the title. I organized models and controllers into distinct files saved under models and controllers folders respectively. Upon trying to establish a connection between them, I received an error stating "ng:areq ...

The form control name cannot be viewed in display mode

When using a reactive form to display information, I encountered an issue where one field in the form group was not rendering the value until the page was refreshed. Here is a simplified version of the code: .ts file private getPhaseParId(id: number) { ...

In the process of creating my initial discord bot, struggling to incorporate advanced functionalities beyond basic commands

I am currently using discord.js and JavaScript to code. I have created a test bot and followed step-by-step guides meticulously, but the bot only responds to basic "ping pong" commands. Whenever I try to add more complex commands, the bot stops functioning ...

Encountering issues with fs.writeFile function in a freshly set up Vue project

After initializing a new Vue project with vue cli, I encountered an error when attempting to write files in the main.js file. Below is the code snippet that caused the issue: const fs = require('fs'); // Data to be written to the file. let dat ...

Attempting to create a button that will only appear for items with a defined value for a specific variable

I am currently facing an issue with a template that needs proper population. The store locator on my website lists pharmacies and displays their relevant information (phone number, address, hours of operation) along with three buttons (view store, view fl ...

Reactivity in Vue 3 with globalProperties

When attempting to migrate a Vue 2 plugin to Vue 3, I encountered an issue in the install function. In Vue 2, I had code that looked like this: install(Vue, options) { const reactiveObj = { // ... }; Vue.prototype.$obj = Vue.observable(reactiveO ...