Closed Bug 1303464 Opened 9 years ago Closed 9 years ago

every browser fails [1,2]==[1,2,3,4].slice(0,2)

Categories

(Firefox :: Untriaged, defect)

48 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: jmichae3, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.0; rv:48.0) Gecko/20100101 Firefox/48.0 Build ID: 20160823121617 Steps to reproduce: start ANY browser including IE9 start debugger (F12 or ctrl-shift-i) into the console, put: [1,2]==[1,2,3,4].slice(0,2) Actual results: false Expected results: true
you cannot compare the elements of arrays with == operator. you need to compare each elements one by one. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality > If both operands are objects, then JavaScript compares internal references > which are equal when operands refer to the same object in memory.
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → INVALID
you can with c++ and other compiled languages, I don't understand any not js...
workaround: function Array.prototype.equals(a) { for (var i=0; i < this.value.length; i++) { if ('object'==typeof(this.value)) { Array.prototype.equals(this.value[i],a[i]); } else { if (this.value[i]!=a[i]) { return false; } } } return true; }
that's not the finished version - but do you want to change this from resolved invalid to resolved-fixed (where is that select option anyway?)?
You need to log in before you can comment on or make changes to this bug.