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))
4
  • Does my answer work for you? Commented Aug 7, 2020 at 0:04
  • yes but i want use find inside of function not in console .. i want function to return the name Commented Aug 7, 2020 at 0:11
  • See the second part of my answer. Commented Aug 7, 2020 at 0:12
  • it works .. thanks so much. Commented Aug 7, 2020 at 0:33

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.