Array#lastIndexOf – fromIndex evaluation
# Rick Waldron (13 years ago)
Allen can confirm for certain, but I suspect this is a bug, which would get filed here: bugs.ecmascript.org
Allen can confirm for certain, but I suspect this is a bug, which would get filed here: https://bugs.ecmascript.org/ Rick On Sat, Nov 3, 2012 at 3:28 PM, Asen Bozhilov <asen.bozhilov at gmail.com>wrote: > According to the spec if fromIndex is NaN or undefined the search will > start from 0. Step 5 of Array.prototype.lastIndexOf performs > ToInteger(fromIndex). > This is in contradiction with String.prototype.lastIndexOf, where even if > I pass a NaN or undefined for position value, the search will start again > from the end of the string. > I am wondering what is the intention of that decision, because it seems > like bug in specification. > Thank you. > > > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121103/cd607cdf/attachment.html>
# Brendan Eich (13 years ago)
Thanks for raising this -- please do file a bug as Rick suggested.
Thanks for raising this -- please do file a bug as Rick suggested. /be Asen Bozhilov wrote: > According to the spec if fromIndex is NaN or undefined the search will > start from 0. Step 5 of Array.prototype.lastIndexOf performs > ToInteger(fromIndex). > This is in contradiction with String.prototype.lastIndexOf, where even > if I pass a NaN or undefined for position value, the search will start > again from the end of the string. > I am wondering what is the intention of that decision, because it > seems like bug in specification. > Thank you. > > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss
According to the spec if fromIndex is NaN or undefined the search will start from 0. Step 5 of Array.prototype.lastIndexOf performs ToInteger(fromIndex). This is in contradiction with String.prototype.lastIndexOf, where even if I pass a NaN or undefined for position value, the search will start again from the end of the string. I am wondering what is the intention of that decision, because it seems like bug in specification. Thank you.