-5

In java, How to compare 2 java objects of type JSObject using a javascript operator like '==' or '==='?

cweiske
  • 30,033
  • 14
  • 133
  • 194
Suntuu
  • 1
  • 1
  • there is no any Operator like `===` in java as in javascript this operator is checking `equal value and equal type` – Prashant Apr 22 '15 at 14:17
  • 2
    possible duplicate of [Does it matter which equals operator (== vs ===) I use in JavaScript comparisons?](http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons) – Ungeheuer Apr 22 '15 at 14:18
  • 2
    `Java != JavaScript` – Markus W Mahlberg Apr 22 '15 at 20:43

2 Answers2

0

In javaScript
object.hasOwnProperty(proName) tells object has or has not the property.

ozil
  • 6,930
  • 9
  • 33
  • 56
0

If you just want to check if two variables or instances point to the same object use:

if (obj1 === obj2)

Or else, if you want to check if the two objects are completely identical with the same properties and methods in the same order and having the same values but not necessarily being the same object, use:

if (JSON.stringify(obj1) === JSON.stringify(obj2))

If the order in which the properties and methods are attached can be different you'd need to loop through all the properties and methods of both objects and check that a corresponding entry exists for the other. Just looping through all the properties and methods of one wouldn't check that there are no extra properties and methods attached to the other.

Got it from: codingforums

Giovanni Di Toro
  • 797
  • 1
  • 14
  • 34