forEach loop not updating array as desired

I’m trying to loop through the consoleOuputParamsOBJ and update a record in my taskparamscompiled list of objects

consoleOuputParamsOBJ

"outputParameters": [
        {
            "name": "00x00",
            "filepath": "D:\\Code\\UnitTest\\ConsoleApp\\1\\00x00.png"
        },
        {
            "name": "00x01",
            "filepath": "D:\\Code\\UnitTest\\ConsoleApp\\1\\00x01.png"
        },
        {
            "name": "00x02",
            "filepath": "D:\\Code\\UnitTest\\ConsoleApp\\1\\00x02.png"
        },

taskparamscompiled updated with current output, it’s updating all the records with the last instance of the record in the consoleOuptutParamsOBJ. I’m trying to get them to update with the correct matching filepath

{
    "process00x00": {
        "-i": "D:\\Code\\UnitTest\\ConsoleApp\\1\\13x23.png",
        "-tr": 16,
        "-tc": 16,
        "-ofr": 16,
        "-ofc": 16,
        "-outfile": "\"D:\\Code\\UnitTest\\ConsoleApp\\Process\\1\""
    },
    "process00x01": {
        "-i": "D:\\Code\\UnitTest\\ConsoleApp\\1\\13x23.png",
        "-tr": 16,
        "-tc": 16,
        "-ofr": 16,
        "-ofc": 16,
        "-outfile": "\"D:\\Code\\UnitTest\\ConsoleApp\\Process\\1\""
    },
    "process00x02": {
        "-i": "D:\\Code\\UnitTest\\ConsoleApp\\1\\13x23.png",
        "-tr": 16,
        "-tc": 16,
        "-ofr": 16,
        "-ofc": 16,
        "-outfile": "\"D:\\Code\\UnitTest\\ConsoleApp\\Process\\1\""
    },

What i’m currently doing, the processname seems to be working since it’s updating that value but the data it’s using to update it with is only the last record from the taskparamscompiled dataset.

 consoleOutputParamsOBJ.forEach((obj) => {
      var processname = dynamicTaskNameBaseOBJ + obj.name;
      filepath = obj.filepath;
      taskparamscompiled[processname]['-i'] = filepath;


    });

4 thoughts on “forEach loop not updating array as desired”

  1. Hi! I understand this is sort of off-topic however I needed to ask.
    Does managing a well-established website such as yours
    take a lot of work? I am completely new to running a blog
    but I do write in my journal on a daily basis. I’d like to start
    a blog so I will be able to share my own experience and
    thoughts online. Please let me know if you have any recommendations or tips for brand new aspiring bloggers.
    Appreciate it! http://www.deinformedvoters.org/hydroxychloroquine

    Reply

Leave a Comment