0

I want to make a function to find specific address as (tokia) after that return name. I tried this code but not give me the name only.

 let  info = [
  {name: "ola",  address: "tokia"},
  {name: "omar",  address: "mokla"},
  {name: "ohod",  address: "gola"}
  ]
function  findNam(info)
{ if(info.address==="tokia")
  { return info.name; }   }
 console.log(info.find(findNam))
Unmitigated
  • 76,500
  • 11
  • 62
  • 80
Pop
  • 31
  • 5

1 Answers1

1

Just access the name property with dot notation. find returns the element that matches the condition, not what you return from the callback.

console.log(info.find(findNam).name)

You can use destructuring to store the name in a variable.

const {name} = info.find(findNam);
console.log(name);
Unmitigated
  • 76,500
  • 11
  • 62
  • 80