首页 > 编程知识 正文

js数组的includes方法,indexof方法参数

时间:2023-05-05 02:10:39 阅读:11285 作者:3685

使用11:数组的索引of方法:字符串类型let str='orange '; str.indexof('o ); //0字符串中字符o出现的位置str.indexof('n ); //3字符串中字符n出现的位置str.indexof('c ); //-1不出现字符串的字符(不匹配的字符为-1)实际上下标为:0----------------let num=2016; num.indexof(2; 如果不对//uncaught typeerror 3360 num.indexofisnotafunctionnumber类型使用索引of方法:必须将number类型转换为字符串类型; 第一种方法: let num='2016 '; num.indexof(2; //0第二种方法:num.tostring(.indexof ) ) 2; //0第三种方法:('num ).indexOf(2) 2; //0在字符串中取出该字符出现的位置; ------------------------arr or arr.index of (orange ); //0数组第一个元素出现' orange '出现的位置arr.indexof('o ); //-1数组中出现o的位置,如果未分配则返回-1。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。