JavaScript: Manipulation des tableaux
Sid Ali BENTIFRAOUINE
Posted on October 4, 2022
Le filter
(ne fait pas le cafè)
let USERS = [
{ id: 1, name: "Paul" },
{ id: 2, name: "Jean-Karim" },
{ id: 3, name: "Jean-Babibel" },
]
// 1. Supprimer "Jean-Karim"
// id: 2
const id_du_user_a_supprimer = 2
USERS = USERS.filter(u => u.id != id_du_user_a_supprimer)
Le map
(ce n'est pas une carte)
// 2. Modifier "Jean-Karim"
// id: 2
const id_du_user_a_editer = 2
USERS = USERS.map((u) => {
if (u.id != id_du_user_a_editer) {
return u
} else {
return {
...u,
name: "Jean-Baptiste",
}
}
})
💖 💪 🙅 🚩
Sid Ali BENTIFRAOUINE
Posted on October 4, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.