title: Check if object is in AngularJS array that is in localStorage
body: <p>I have this angularjs array: <code>$scope.fav = []</code> where items (objects) get added with to it on a function call. an example of these objects are <code>{quote: "Some text", controller: some_controller}</code> When I add a new object to the array, the array is saved in localstorage. The array works exactly how I want it to except when I try to print it in console.log() i get many [object, Object], which I just assumed is the way it is printed. This isn't the main issue though because the array works how it needs to. </p>
  
  <p>The issue I am having is with trying to find if an object is already in an array. I have tried</p>
  
  <p><code>if ($scope.fav.indexOf({quote: q, controller: c}) == -1)</code> </p>
  
  <p>and this did not seem to work because every object going in was index -1 even if it was already in the array. I presume this is because it is not reading the object correctly.</p>
  
  <p>Lastly I have resorted to this function:</p>
  
  <pre><code>$scope.containsObject = function(obj, list) {
  var i;
  for (i = 0; i &lt; list.length; i++) {
      if (list[i] === obj) {
          return true;
      }
  }
  
  return false;
  </code></pre>
  
  <p>}</p>
  
  <p>which checks if the object is in the array. Here is how I call it:</p>
  
  <pre><code>$scope.addToFav = function(q, c) {
      $scope.value = $scope.containsObject({quote: q, controller: c}, $scope.fav)
      console.log($scope.value);
  </code></pre>
  
  <p>}</p>
  
  <p>I keep getting a negative value for $scope.value even if the object is in the array.
  Sorry for the long complicating explanation.</p>
  
  <p>Thank you for your insight,
  Ben</p>