1

I have already existed array of object values now when i delete dataItem dataItem has same properties that i have in selectedOwners so if dataItem selected value matched i want to delete that object from selectedOwners array.

How can i achieve that task using AngularJs or Javascript ?

ctrl.js

  var selectedOwners = [{"fullName":"Johnson, Rocio","workerKey":3506},{"fullName":"Johnson, John S.","workerKey":571}];

   $scope.deleteOwner = function(dataItem){
              angular.forEach(selectedOwners,function(val,index){
                if(val === dataItem){
                  selectedOwners.splice(index,1);
                }
              })
            }
hussain
  • 6,587
  • 18
  • 79
  • 152
  • 1
    Possible duplicate of [Remove a particular element from an array in JavaScript?](http://stackoverflow.com/questions/5767325/remove-a-particular-element-from-an-array-in-javascript) – manniL Mar 08 '16 at 22:57

1 Answers1

0

Unfortunately in Javascript you don't have many instrument for a good equality checking, and === isn't enough, === don't force javascript to convert the two operand in order to perform the equality check on the same type of object, we let say that in this way you have true if the two objects have the same memory reference false otherwise. For this reason you should decide the your equality criteria and wrap this login in a function. I discourage to use something like this Object.prototype.equals because in the sway you will have the same behavior for all objects in your script

the rest of code that you had post is good in my opinion but you have implements a equality checking

I hope that this can help you

Valerio Vaudi
  • 4,199
  • 2
  • 24
  • 23
  • I am new to javascript and angularJs so looking for feasible solution to check object equality – hussain Mar 08 '16 at 21:57
  • even a simple function like this could be usefull function equality (obj, obj2) { return obj.fullName===obj2.fullName && obj.workerKey===obj2.workerKey } – Valerio Vaudi Mar 08 '16 at 22:27