Funkcja find i undefined przy użyciu spread

Funkcja find i undefined przy użyciu spread
Mateuszto
  • Rejestracja: dni
  • Ostatnio: dni
  • Lokalizacja: Poznań
  • Postów: 163
0

Cześć, wie ktoś czemu userThreeName = undefined, wydaje mi się, że chodzi o zwracanie z find, natomiast już sam się pogubiłem

Kopiuj
const userToFind = 10;
const allUsers = [
  { name: 'Mat', id: 200 },
  { name: 'Pat', id: 300 },
  { name: 'Kat', id: 10 }
];

const userThree = allUsers.find(({ id }) => id === userToFind);

const { userThreeName, userThreeId } = userThree;
console.log(`Szukany użytkownik to ${userThreeName}`);
MA
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 644
1
Kopiuj
const userToFind = 10;
const allUsers = [
  { name: 'Mat', id: 200 },
  { name: 'Pat', id: 300 },
  { name: 'Kat', id: 10 }
];


const { name: userThreeName, id: userThreeId } = userThree;
console.log(`Szukany użytkownik to ${userThreeName}`);
G5
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 31
0
Kopiuj
 const userToFind = 10;
  const allUsers = [
    { name: 'Mat', id: 200 },
    { name: 'Pat', id: 300 },
    { name: 'Kat', id: 10 },
  ];

  const user = allUsers.find(obj => obj.id === userToFind);
  console.log(user);
  const { name, id } = { ...user };
  console.log(name, id);

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.