18. Stable Array.prototype.sort()
Starting with ECMAScript 2019, the Array method .sort()
is guaranteed to be stable. What does that mean (as proposed by Mathias Bynens)?
It means that if elements that are considered equal by sorting (not necessarily in any other way!) then sorting does not change the order of those elements. For example:
Two objects have the same .key
, 'b'
. Their order will always be preserved by .sort()
. One benefit is that a unit test where stability matters, now works the same across engines.
当前内容版权归 exploringjs.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 exploringjs.com .