title: Javascript function can console.log the value but not return it
body: <p>I have an array of objects:  </p>
  
  <pre><code>let array = [
    {
      id: 0,
      name: "Name0"
    },
    {
      id: 1,
      name: "Name1"
    }
  ]
  </code></pre>
  
  <p>and a function that iterates through the array, searches for the object with a specified id property and should return the objects name property:</p>
  
  <pre><code>function getName1(id) {
    array.map((object) =&gt; {
      if(object["id"] === id)
        return object["name"]
    })
  }
  </code></pre>
  
  <p>However this code</p>
  
  <pre><code>console.log(getName1(0)) // undefined
  </code></pre>
  
  <p>returns undefined</p>
  
  <p>If I simply console.log the name of the object inside the function</p>
  
  <pre><code>function getName2(id) {
    array.map((object) =&gt; {
      if(object["id"] === id)
        console.log(object["name"])
    })
  }
  </code></pre>
  
  <p>it works perfectly fine:</p>
  
  <pre><code>getName2(0) // "Name1"
  </code></pre>
  
  <p>I basically just want </p>
  
  <pre><code>getName1(0)
  </code></pre>
  
  <p>to return </p>
  
  <pre><code>Name0
  </code></pre>
  
  <p>How can I achieve this?</p>