0

What am I doing wrong here? I am trying to get unique values in my array of objects. First time it gives -1 and 2nd time also it gives -1 and so it is pushing duplicate objects into the array:

output.inventory.indexOf({"KUNNR": resultSet[row].KUNNR,"LOCATION": resultSet[row].LOCATION,"MATERIAL": resultSet[row].MATERIAL})
Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
Satya
  • 1
  • You can do `"abcde".indexOf("b")` and `[1,2,3,4,5].indexOf(3)`, but it doesn't simply work with objects, that's more complicated than that. I've pointed your question to a duplicate. – Jeremy Thille Jan 01 '21 at 07:43
  • -1 simply means it hasn't matched, nothing to do with duplicates. As @JeremyThille2 says objects are more complicated. If you had an array of references to objects and you searched for an object reference you could find one, but you are searching for what amounts to a new object so it will not find it in your array. – A Haworth Jan 01 '21 at 07:50
  • The array contains say 3 objects and I am checking with an object, which is exactly same as one of those 3 objects. includes method or indexOf method always return false. So it means that object shows exactly same values in debugging, but javascript is not matching the object with array of objects. How can we resolve this challenge? – Satya Jan 01 '21 at 23:46

0 Answers0