Skip to content

Array.prototype.find() returns -1 instead of undefined #178

Description

@theetrain

The default behaviour of Array.prototype.find is to return the first matching value or undefined if not found. Collections.js returns -1 instead of undefined, which causes an unexpected issue with truthiness and coercion:

Standard behaviour:

[].find(a => true) // undefined
!![].find(a => true) // false

Collections.js behaviour:

[].find(a => true) // -1
!![].find(a => true) // true

I'm only curious why this decision was made.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions