DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Sid Ali BENTIFRAOUINE
Sid Ali BENTIFRAOUINE

Posted on

JavaScript: Manipulation des tableaux

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)
Enter fullscreen mode Exit fullscreen mode

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",
    }
  }
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

DEV has this feature:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›