frankcollins3 / PHPokedex

react concepts
0 stars 0 forks source link

loop characters are unretrievable by bracket notation [11:38am] #44

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago
export default async function allDataAllPokemonFunc () {
  let predata_allAPI = await fetch(`http://localhost:5000/pokemon?query={allAPIpokemon{name,poke_id}}`)
  let predata = await predata_allAPI.json()
  let allAPI = predata.data.allAPIpokemon
  let bucket = ['test', 'othertest'];    

  const loopAndPush = async () => {
      await allAPI.forEach(async(pokemon) => {
        let predata_allDataAllPoke = await fetch(`http://localhost:5000/pokemon?query={allDataAllPokemon(name:"${pokemon.name}"){name,poke_id,type,moves,abilities,image}}`)
        // let predata_allDataAllPoke = await fetch(`http://localhost:5000/pokemon?query={allDataAllPokemon(name:${pokemon.name}){name,poke_id}}`)
        let allDataAllPoke = await predata_allDataAllPoke.json()            
        allDataAllPoke = allDataAllPoke.data.allDataAllPokemon
        // console.log('allDataAllPoke')
        // console.log(allDataAllPoke)

        // let myobject = {name: allDataAllPoke, image: allDataAllPoke.image }
        // console.log('myobject')
        // console.log(myobject)

        await bucket.push(allDataAllPoke)                    
      })
    }

    const returnbucket = async () => {return await bucket}

    const pushAndReturn = async () => {
      await loopAndPush()
      console.log(bucket[0])
      // console.log(bucket[1])
      return returnbucket()
    }
    return pushAndReturn()

    // return bucket
}

produces this output:

(2) ['test', 'othertest'] 0 : "test" 1 : "othertest"

{name: 'bulbasaur', poke_id: 1, type: 'grass', moves: 'razor-wind', abilities: 'overgrow', …} {name: 'ivysaur', poke_id: 2, type: 'grass', moves: 'swords-dance', abilities: 'overgrow', …} {name: 'venusaur', poke_id: 3, type: 'grass', moves: 'swords-dance', abilities: 'overgrow', …} {name: 'charmeleon', poke_id: 5, type: 'fire', moves: 'mega-punch', abilities: 'blaze', {name: 'charmander', poke_id: 4, type: 'fire', moves: 'mega-punch', abilities: 'blaze', … {name: 'charizard', poke_id: 6, type: 'fire', moves: 'mega-punch', abilities: 'blaze', …} {name: 'squirtle', poke_id: 7, type: 'water', moves: 'mega-punch', abilities: 'torrent', …}



where the ['test', 'state'] variables are accessible.
but somehow the loop data is pushed into such a context within the array
that the characters are unretrievable by bracket notation
frankcollins3 commented 1 year ago

Screen Shot 2023-05-12 at 11 37 43 AM

frankcollins3 commented 1 year ago

first proposed approach:

let bucket = [];

I already populated initial variable declaration like so: let bucket = ['test', 'anothertest']

loop.forEach( (data) => bucket.push(data)

'test' and 'another test' are retrievable by bracket notation and are returned together at the index of [0] bucket[1] becomes the span of API data

but without any of those endpoints being returnable.

[11:41pm]