ITERATION OPTIONS for putting manifests into array in the postTrucks function

PHOTO EMBED

Fri Mar 12 2021 19:52:26 GMT+0000 (UTC)

Saved by @stephanieraymos

  //Fetching the trucks db from the API link above //^----POST (ADD INVENTORY)----
  const postTrucks = async () => {
    if ((truckName != "", truckPrice != "")) {
      try {
        const response = await fetch(
          "http://143.110.225.28/api/v1/inventory/",
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify({
              truckName: truckName,
              truckPrice: truckPrice,
              truckContents: truckContents,
              truckManifest: truckManifest,
              id, id
            }),
          }
        );
        // {trucks.map((truck) => {
        //   return (
        //     <li key={truckManifest.id}>{truckManifest.name}</li>
        //   )
        // })}
        // let i;
        // for (i = 0; i < truckManifest.length; i++) {
        //   file += truckManifest[i];
        // }
        return response.json();
      } catch (error) {
        console.log(error);
      }
    }
  };


//OPTION ONE: MAP
        {trucks.map((truck) => {
           return (
             <li key={truckManifest.id}>{truckManifest.name}</li>
           )
         })}

//OPTION TWO: FOR LOOP
         let i;
         for (i = 0; i < truckManifest.length; i++) {
           file += truckManifest[i];
         }      
content_copyCOPY