rbi-learning / Today-I-Learned

1 stars 0 forks source link

Today I learned 8/12 #120

Open amatheus000 opened 4 years ago

amatheus000 commented 4 years ago

Morning exercise

  1. We used the .find function to identify elements within an object that have determined characteristic defined in a function previously.

const firstTurtleWithHasInHisDescription = turtles.find (turtle => turtle.description.includes("has"))

  1. We used the findIndex to identify elements positions in an array. This is very helpful for big arrays and we need to highlight the nth element inside an arrangement.

const indexOfTheTurtleWhoseWeaponEndsWithI = turtles.findIndex(turtle => turtle.weapon.endsWith("i"))

Afternoon Work

We established an API and learned how to save data, and retrieve it and have it shown in the front end.

  1. When editing text in an array we use: PATCH in combination with the fetch function

    fetch(url, { method: "PATCH", headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify(body)} }

  2. When Deleting an element in an array: fetch(url, { method: "DELETE", headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } })

Notes/Shortcuts:

When we want to show as checked element or just to leave it blank we can use the following code:

image