Javascript Hijinks... a question for the code gurus.

Edu-Money

void.face

Contributor
Joined
Aug 7, 2021
Messages
72
'ello!

So I've been working on a funnel for a few weeks now, and I have all of the layout and basic functions done. It's essentially a glorified chat lander that is arranged into chat lobby -> member bio -> simulated chat.

I coded the whole thing using a single member with the intention of coming back through once everything was done and add the code to display multiple members.

What I'm doing is storing member names, ages, bios, and scripted chat messages in a JSON file. The trouble I'm having is wrapping my head around how to use the fetch/response stuff to get my data out of the JSON file and into an array where I can use it.

The code below is producing the result I want, but it's sloppy as hell.

Here's the JSON file:
JavaScript:
[
    {
          "name": "Bill",
         "age": "44"
     },
     {
         "name": "Ted",
         "age":  "45"
    }
]

Here's the script I'm using to populate an array from the JSON file:

JavaScript:
<script>
          let a = [];

          fetch('/my.json')
              .then(response => response.json())
              .then(data => { a  = [...data] });

         setTimeout(function ()  { console.log(a); }, 500);
</script>

The problem here is that I'm copying
 
To view the premium content in our affiliate marketing forum (including this awesome thread), you must first register and upgrade your account. Register today and become a part of our amazing community!
Top