I have 2 different javascript object :  key = {   id : 3,    name : "Leroy",    class : "A",    address : "IDN",    age : "17" }   and ...  answer = {   id : 3,    class : "A",    name : "Leroy",    age : "17",    address : "IDN" }   What I wanted to do is to compare answer object with key object using (===) or (==) and will return true, even when the answer object key order is mixed, but as long as the value within each key is the same, it will still return true.  The condition will return false if one of the key in answer object and its value is not present, or there is a new key and value set inside the answer object.  Any help would be appreciated!
11800
A strict equality operator will tell you if two object types are equal. However, is there a way to tell if two objects are equal, much like the hash code value in Java?  Stack Overflow question  is similar to this question, but requires a more academic answer. The scenario above demonstrates why it would be necessary to have one, and I'm wondering if there is any equivalent solution.
79063
I have an ArrayList of objects in Java.  The objects have four fields, two of which I'd use to consider the object equal to another.  I'm looking for the most efficient way, given those two fields, to see if the array contains that object.  The wrench is that these classes are generated based on XSD objects, so I can't modify the classes themselves to overwrite the .equals.    Is there any better way than just looping through and manually comparing the two fields for each object and then breaking when found?  That just seems so messy, looking for a better way.  Edit: the ArrayList comes from a SOAP response that is unmarshalled into objects.
1141
I have a JavaScript object. Is there a built-in or accepted best practice way to get the length of this object? const myObject = new Object(); myObject[&quot;firstname&quot;] = &quot;Gareth&quot;; myObject[&quot;lastname&quot;] = &quot;Simpson&quot;; myObject[&quot;age&quot;] = 21;
81320
I am trying to add key value pair in the below JSON object, but it is getting added in the wrong way, is there any way i can add to each object a new  key value pair, that will help me to complete the req. JSON as follow : var object =[       {          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;       } ]  code i am using to add the new key value pair : for (let i = 0; i &lt; object.length; i++) {             object[i]['ABC'] = [i];         }  Actually expected should be: var object =[       {          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;,          &quot;ABC&quot;: &quot;0&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;,          &quot;ABC&quot;: &quot;1&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;          &quot;ABC&quot;: &quot;2&quot;       } ]  the final value i am getting as below: [&quot;0&quot;:{          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;,           },    &quot;1&quot;:{          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;              },    &quot;2&quot;:{        &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;    }   ]  kindly someone help me out to achieve this
14108
Basically, I'm trying to create an object of unique objects, a set. I had the brilliant idea of just using a JavaScript object with objects for the property names. Such as,  set[obj] = true;   This works, up to a point. It works great with string and numbers, but with other objects, they all seem to "hash" to the same value and access the same property. Is there some kind of way I can generate a unique hash value for an object? How do strings and numbers do it, can I override the same behavior?
98914
The MSDN documentation on  describes 3 contradicting rules for how the method should work.     If two objects of the same type represent the same value, the hash function must return the same constant value for either object. For the best performance, a hash function must generate a random distribution for all input. The hash function must return exactly the same value regardless of any changes that are made to the object.   Rules 1 &amp; 3 are contradictory to me.  Does Object.GetHashCode() return a unique number based on the value of an object, or the reference to the object. If I override the method I can choose what to use, but I'd like to know what is used internally if anyone knows.
22278
I have an object x. I'd like to copy it as object y, such that changes to y do not modify x. I realized that copying objects derived from built-in JavaScript objects will result in extra, unwanted properties. This isn't a problem, since I'm copying one of my own literal-constructed objects.  How do I correctly clone a JavaScript object?
8867
When should I use -eq vs = vs ==  e.g.    [[ $num -eq 0 ]]  [[ $num = 'zzz' ]]   I've observed a pattern of using -eq (and -ne, etc.) for numbers and = for strings.  Is there a reason for this and when should I use ==
52231
If I had a dictionary dict and I wanted to check for dict['key'] I could either do so in a try block (bleh!) or use the get() method, with False as a default value.  I'd like to do the same thing for object.attribute. That is, I already have object to return False if it hasn't been set, but then that gives me errors like     AttributeError: 'bool' object has no attribute 'attribute'
32595
I need to set a constant value as true or false for the particular scenario not sure correct working or not const test = data.findIndex(d =&gt; d.Fname === '' &amp;&amp; d.Lname === '') &lt; 0 ? false : true;  if fname and Lname both are blank then i want to set test as false not sure what is happening here.
42562
How could I go about detecting (returning true/false) whether an ArrayList contains more than one of the same element in Java?  Many thanks, Terry  Edit Forgot to mention that I am not looking to compare "Blocks" with each other but their integer values. Each "block" has an int and this is what makes them different. I find the int of a particular Block by calling a method named "getNum" (e.g. table1[0][2].getNum();
89294
Let's say I have a Ruby class:  class MyClass   def self.property     return "someVal"   end    def self.property=(newVal)     # do something to set "property"     success = true      return success # success is a boolean   end end   If I try and do MyClass.property=x, the return value of the whole statement is always x. It is a convention in a lot of C-based/inspired languages to return a boolean "success" value - is it possible to do this for a setter using the "equals syntax" in Ruby?  Furthermore - if this isn't possible, why not? Is there any conceivable downside to allowing an "equals setter" operation return a value?
23702
Just curious:    4 instanceof Number => false new Number(4) instanceof Number => true?   Why is this? Same with strings:    'some string' instanceof String returns false new String('some string') instanceof String => true String('some string') instanceof String also returns false ('some string').toString instanceof String also returns false   For object, array or function types the instanceof operator works as expected. I just don't know how to understand this.  [new insights]  Object.prototype.is = function() {         var test = arguments.length ? [].slice.call(arguments) : null            ,self = this.constructor;         return test ? !!(test.filter(function(a){return a === self}).length)                : (this.constructor.name ||                   (String(self).match ( /^function\s*([^\s(]+)/im )                     || [0,'ANONYMOUS_CONSTRUCTOR']) [1] ); } // usage var Newclass = function(){};  // anonymous Constructor function var Some = function Some(){}; // named Constructor function (5).is();                     //=&gt; Number 'hello world'.is();           //=&gt; String (new Newclass()).is();        //=&gt; ANONYMOUS_CONSTRUCTOR (new Some()).is();            //=&gt; Some /[a-z]/.is();                 //=&gt; RegExp '5'.is(Number);               //=&gt; false '5'.is(String);               //=&gt; true
82893
Is it true that I cannot have OR or AND operators in if statements in APEX?  I have an object that has a picklist Code__c, and I need to execute some code if the code is set to either A or B.  How would I write something like:  if(pc.Code__c = 'A' || pc.Code__c = 'A') { }   Tia.
92960
As can be seen in the Mozilla changlog for JavaScript 1.7 they have added destructuring assignment. Sadly I'm not very fond of the syntax (why write a and b twice?):  var a, b;   [a, b] = f();   Something like this would have been a lot better:  var [a, b] = f();   That would still be backwards compatible. Python-like destructuring would not be backwards compatible.  Anyway the best solution for JavaScript 1.5 that I have been able to come up with is:  function assign(array, map) {     var o = Object();     var i = 0;     $.each(map, function(e, _) {         o[e] = array[i++];     });     return o; }   Which works like:  var array = [1,2]; var _ = assign[array, { var1: null, var2: null }); _.var1; // prints 1 _.var2; // prints 2   But this really sucks because _ has no meaning. It's just an empty shell to store the names. But sadly it's needed because JavaScript doesn't have pointers. On the plus side you can assign default values in the case the values are not matched. Also note that this solution doesn't try to slice the array. So you can't do something like {first: 0, rest: 0}. But that could easily be done, if one wanted that behavior.  What is a better solution?
95768
Is there any way in javascript to create a "weak reference" to another object?   Can anyone think of a way to implement this  behavior in javascript?
2525
My  has failed me.  In Python, are the following two tests for equality equivalent?  n = 5 # Test one. if n == 5:     print 'Yay!'  # Test two. if n is 5:     print 'Yay!'   Does this hold true for objects where you would be comparing instances (a list say)?  Okay, so this kind of answers my question:  L = [] L.append(1) if L == [1]:     print 'Yay!' # Holds true, but...  if L is [1]:     print 'Yay!' # Doesn't.   So == tests value where is tests to see if they are the same object?