The curriculum talks about how to add new key-value pairs to an object: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object
Ha!
Thank you…
So I got the data added correctly with the code shown below…
let newData = (myObject.data[textIndex2++].text2 =
${responseAItoJson}
);console.log(newData); var newData2 = JSON.stringify(myObject);
^^ However, once I run 3 cycles, and I go to create the json file, then I only come out with the last key/value pair of the last run…
How could I append/hold each value after each cycle? so, that when I go create the json file the object holds the complete information from all runs?
I got it working…
Took the initial data file out of the loop… that way it doesn’t re-loop it with the initial data all the time…
It was a simple code…
Why it took me so long??? What are my excuses???
-
I started by trying to modify the file itself instead of converting it into an object.
-
Unfortunately I found a bad code in the internet that I tried to copy.
-
I forgot about ++ values to put the code in the right place.
-
Gotta pay more attention what items I put inside my setInterval() function or I might never get it to work…
-
I might never learn…
This can send you down a big rabbit hole. There’s lots of code out there that’s bad or a bad fit for your needs.
This stuff is complicated and takes time to learn.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.