.indexOf method(in javascript) returns wrong result when called with keyword array

Description

The following expression should return "1":

(.indexOf (to-array [:a :b :c]) :b)

but actually the result is -1.
Note that this method call behaves normally with other type of array:

>(.indexOf (to-array ["a" "b" "c"]) "b")
>1

So I guess there might something wrong with the type Keyword.
Anyone have a look at this?

Environment

Windows, clojurescript-2755

Activity

Show:
Francis Avila
February 2, 2015, 2:18 PM

Array.prototype.indexOf uses strict equality (js === operator) to compare search item with array items. Keywords are Objects, and the same keyword-equal object may not be the same identical object. Non identical objects never compare strictly equal in js and there is nothing that can be done to change this.

Use something other than indexOf to find your item. You need to compare items with the cljs = function or with keyword-equal?

David Nolen
February 2, 2015, 3:40 PM

This is not a bug.

Declined

Assignee

Unassigned

Reporter

import

Labels

Approval

None

Patch

None

Priority

Major