DEV Community

Discussion on: Most efficient way to add to an array.

 
alexluong profile image
Alex Luong

Hey there,

Sorry for the late response. Quite a long July 4th weekend for me.

I get what you want to do now. So let's assume you have a file callded data.json with your array in it. What I would do is:

  • Create an API server (using Node/Python, Java, etc) that can read + write data to your computer
  • When you change data in your admin/maintenance tool, in your React front end, you will send an AJAX request to update that data
  • Your API server will then write the new data to your disk

That's quite a process. Is there a problem with editing data from the JSON file itself?

Thread Thread
 
cmcco91 profile image
cmcco91

After further investigation I have discovered that what I’m asking is basically impossible or not right either way. And so now I think I do need to be looking at using json and passing that data into my array. So now the question is the best way for updating and adding to a json file. I’m thinking for now I’m best to just use. Json generator app/page and just copy and paste it in. But I would like to have a form where new listings can fill out their information and submit it and the form send me the output via email in json form. That way I can review it and then add it to the correct json file.

What are your thought on this new idea? Thanks for your time.

Thread Thread
 
alexluong profile image
Alex Luong

I'm not sure why you need a UI to add data to JSON. What's wrong with edit the array inside your text editor?

Thread Thread
 
cmcco91 profile image
cmcco91

That’s what I’m going to do for now mate, but I’m talking about thousands of new objects being added. I just thought there has to be a more simplified and faster way of going about it. I appreciate your help.