IE why would code like
var strArr = ["a", "b"];
console.log(strArr.reverse() === strArr ? true : false);
print true if the reversed array has a different order?
Because reverse reverses the array IN PLACE, so you are comparing the array with itself.
Actually the Array.prototype.reverse() method morphs the original array to it's reverse and then in addition to that returns a "reference" to this morphed array. Hence the result and the morphed original array becomes the same.
If anyone had asked me before developing this method i would request to keep the original as it is and return a reversed array; alas apparently it wasn't my call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With