Funkcja find i undefined przy użyciu spread

0

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

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}`);
1
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}`);
0
 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.