Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>in</code> operator returns true if the property is in the object. This includes a lookup right up through the prototype chain. For example:</p> <pre><code>Object.prototype.k = 5; f = {}; 'k' in f; // true </code></pre> <p>Even though <code>f</code> is an empty object, it's prototype (as all types in JS) includes that of <code>Object</code>, which has the property <code>'k'</code>.</p> <p>Although you didn't ask, a useful function here to check the object's own properties only, is <code>.hasOwnProperty()</code>, so in our example above:</p> <pre><code>f.hasOwnProperty('k'); // false, that's more what we would expect </code></pre> <p>Although for arrays you don't (usually) want to iterate over all properties, since these properties may include things other than index values, so both for reasons of performance and expected behaviour, a regular <code>for(var i=0;i&lt;n;i++)</code> should be used.</p> <p>As such, if you're using arrays go with <code>in_array_orig</code>, and for objects where you are interested in their properties, use <code>in_array_new</code> (which should be renamed appropriately, <code>in_obj</code> or something).</p> <p>In addition, <code>[1] == [1]</code> returns false since the two objects/arrays are not the <em>same</em> object. Indeed each of their properties and indexes have the same value, although they aren't sitting at the same place in memory, and thus are not considered equal. You can easily build (<a href="https://stackoverflow.com/questions/1068834/object-comparison-in-javascript">or find on the net</a>) a deep search <code>equals()</code> routine to check whether two objects/arrays are indeed equal <em>in value</em> (as opposed to address).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload