0

Hi

Hi! Thanks in advance for your answer, today I was creating a method for my class with name findOne, I'm using an arrow function with the method .find, but is going to return undefined if my code is like the next one:

findOne(id) { return this.products.find((item) => {item.id === id}); }

But is going to work if I don't use the brackets "{}":

findOne(id) { return this.products.find((item) => item.id === id); }

I thought that it was along the same lines, so I want to ask this community. Thanks! I resolved already my issue, but I want to know why is happening

1 Answers1

0

let obj = [{
    id: 1,
    name: 'foo'
  },
  {
    id: 2,
    name: 'abc'
  },
  {
    id: 3,
    name: 'foo1'
  }
];

function findOne(id) {
  return obj.find((item) => {
    return item.id === id
  });
}

console.log(findOne(2));