Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第902天 请解释下[1,2,3,4,5].indexOf('3')的结果 #4533

Open
haizhilin2013 opened this issue Oct 3, 2021 · 6 comments
Open

[js] 第902天 请解释下[1,2,3,4,5].indexOf('3')的结果 #4533

haizhilin2013 opened this issue Oct 3, 2021 · 6 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第902天 请解释下[1,2,3,4,5].indexOf('3')的结果

3+1官网

我也要出题

@haizhilin2013 haizhilin2013 added the js JavaScript label Oct 3, 2021
@ferrinweb
Copy link

indexOf() compares searchElement to elements of the Array using strict equality (the same method used by the === or triple-equals operator).

mdn indexOf

@yj510132642
Copy link

-1 因为数组里面是数字你找的是字符串 而且比较===比较 不是 == 不会隐式转换

@Cason35
Copy link

Cason35 commented Oct 13, 2021

结果为 -1,因为indexOf函数的比较为 === ,需要值,类型都相等

@hyj443
Copy link

hyj443 commented Oct 19, 2021

-1
因为 indexOf使用 严格相等 来判断要查找的元素 与 数组中元素之间 的关系

@2531800823
Copy link

-1 因为数组里没有字符串, indexOf 要找的是字符串,找不到就返回-1

@WangXi01
Copy link

字符串模板不会计算,所以还是展示原来的内容[1,2,3,4,5].indexOf('3')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

7 participants