title: Array Mapping in AngularJs
body: <p>I have two <strong>arrays</strong> </p>
  
  <pre><code>$scope.tags =  [{ "id": 1, "name": "python" }, { "id": 2, "name": "NodeJs" }, { "id": 3, "name": "git" }]
  </code></pre>
  
  <p>Other one is</p>
  
  <pre><code>$scope.skillsInterested = [1,2];
  </code></pre>
  
  <p>What is want to do ?</p>
  
  <p><strong>How can i map the above arrays and print only names of the id's in</strong><code>$scope.skillsInterested</code></p>
  
  <p>I want to print names in <strong>first array</strong> only the id's present in second.</p>
  
  <p>I have tried this after getting several answers </p>
  
  <pre><code>var tag_map = {};
  for (var x = 0; x &lt; $scope.tags.length; x++) {
  tag_map[$scope.tags[x]['id']] = $scope.tags[x]['name'];
  }
  $scope.skillsInts = $scope.skillsInterested.map(function(x) {
  return tag_map[x]
  </code></pre>
  
  <p>On running console.log</p>
  
  <pre><code>console.log("Result", tag_map);
  </code></pre>
  
  <p>It sometimes give result sometimes it gives 'map' of undefined.</p>
  
  <pre><code>TypeError: Cannot read property 'map' of undefined
  at controllers.js:141
  at angular.js:16383
  at m.$eval (angular.js:17682)
  at m.$digest (angular.js:17495)
  at m.$apply (angular.js:17790)
  at l (angular.js:11831)
  at J (angular.js:12033)
  at XMLHttpRequest.t.onload (angular.js:11966)
  </code></pre>
  
  <p>Thanks in advance. </p>