Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For one, this line of code:</p> <pre><code>if('object'==typeof(e)) </code></pre> <p>is like this in your code example:</p> <pre><code>if('object'==typeof(3)) </code></pre> <p>which is </p> <pre><code>if('object'=='number') </code></pre> <p>which will never match.</p> <p>I would also ask why you're trying to wrap a normal array in a jQuery object. It would be better to just use a method that operates on an array.</p> <p>As a global function, you could do it like this:</p> <pre><code>function removeArrayElement(array, itemToRemove) { for (var i = 0; i &lt; array.length; i++) { if (array[i] === itemToRemove) { array.splice(i, 1); break; } } } var x = ['a','b','c','d','e']; removeArrayElement(x, 'c'); </code></pre> <p>As a global method on the jQuery object, you could do it like this:</p> <pre><code>$.removeArrayElement = function(array, itemToRemove) { for (var i = 0; i &lt; array.length; i++) { if (array[i] === itemToRemove) { array.splice(i, 1); break; } } } var x = ['a','b','c','d','e']; $.removeArrayElement(x, 'c'); </code></pre> <p>As a method on the Array object, you could do it like this:</p> <pre><code>Array.prototype.removeElement = function(itemToRemove) { for (var i = 0; i &lt; this.length; i++) { if (this[i] === itemToRemove) { this.splice(i, 1); break; } } } var x = ['a','b','c','d','e']; x.removeElement('c'); </code></pre> <p>Working example of the prototype method here: <a href="http://jsfiddle.net/jfriend00/tEXWH/" rel="nofollow">http://jsfiddle.net/jfriend00/tEXWH/</a></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.
 

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