返回前面起第一个字符的位置
indexOf(“字符”);
它是从前面开始数(从左边开始数),而且只找第一个,然后返回该字符的位置,索引号都是从0开始的。返回的是个数值。
var txt = “abcdefg”;
alert(txt.indexOf(“d”));结果是3
如果找不到该字符 返回-1

返回后面起第一个字符的位置
lastIndexOf(“字符”)
从后面开始数
var txt = “abcdef”;
alert(txt.lastIndexOf(“d”)) 结果是3
返回的值,还是从左边开始数的索引号

函数indexOf()和lastIndexOf()的更多相关文章

  1. ES6 数组遍历方法的实战用法总结(forEach,every,some,map,filter,reduce,reduceRight,indexOf,lastIndexOf)

    目录 forEach every some map filter reduce && reduceRight indexOf lastIndexOf 前言 ES6原生语法中提供了非常多 ...

  2. js中字符串函数indexOf与search的区别

    IndexOf()方法是用来判断一个字符串是否存在于一个更长的字符串中.从长字符串左端到右端来搜索,如果存在该子字符串就返回它所处的位置(即索引).如果在被搜索的字符串没有找到要查找的字符串返回-1. ...

  3. 转:C#中String类的几个方法(IndexOf、LastIndexOf、Substring)

    String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引.搜索从指定字符位置开始,并检查指定数量的字符位置. ...

  4. IndexOf、LastIndexOf、Substring的用法

     String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引.搜索从指定字符位置开始,并检查指定数量的字符位置 ...

  5. C# 二进制字节流查找函数IndexOf

    C# 二进制字节流查找函数IndexOf /// <summary> /// 报告指定的 System.Byte[] 在此实例中的第一个匹配项的索引. /// </summary&g ...

  6. C#中String类的几个方法(IndexOf、LastIndexOf、Substring)

    String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引.搜索从指定字符位置开始,并检查指定数量的字符位置. ...

  7. java中substring和indexof() 和lastindexof()

    java中substring和indexof() 和lastindexof() str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字 ...

  8. Javascript数组的indexOf()、lastIndexOf()方法

    在javascript数组中提供了两个方法来对数组进行查找,这两个方法分别为indexOf(),lastIndexOf(). 这两个方法都有两个参数,第一个参数为需要查找的项,第二个参数则是查找的起始 ...

  9. indexOf和lastIndexOf的使用

    indexOf()和 lastIndexOf()是返回位置index的两个方法:都是接收两个参数,其中,indexOf()方法从数组的开头(位 置 0)开始向后查找:lastIndexOf()方法则从 ...

随机推荐

  1. animate和translate

    transition, transform, tanslate,animation分别为过渡,变换,平移.动画.transform的属性包括:rotate() / skew() / scale() / ...

  2. maven项目启动报错;class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not exist

    项目启动报了一堆错误,其实都是class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not ...

  3. Mysql初级第二天(wangyun)

    SQL 1.LIKE 操作符 SELECT 列名称 FROM 表名称 WHERE 列 LIKE 值('N%'/'%N%'/'%N','N_') SELECT 列名称 FROM 表名称 WHERE 列 ...

  4. PHP 图片缩放类

    <?php /** * 图片压缩类:通过缩放来压缩. * 如果要保持源图比例,把参数$percent保持为1即可. * 即使原比例压缩,也可大幅度缩小.数码相机4M图片.也可以缩为700KB左右 ...

  5. SpringMVC学习笔记1

    1:IntelliJ新建Maven工程 2:pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmln ...

  6. javadoc中{@link}与@see的简单使用以及区别

    因为公司的测试直接对着java api进行外部服务的测试,故最近对javadoc的要求从0变成了严重依赖,有些时候在javadoc不得不引用其他class,以便更加清晰的说明上下文以及含义,发现指向别 ...

  7. shell 变量相关的命令

    变量="变量" readonly 变量名="变量"  表示设置该变量为只读变量 ,这个变量不能别改变 echo $变量名 set  显示本地所有的变量 unse ...

  8. error C4996: Function call with parameters that may be unsafe – this call relies on the caller to ch

    在加入QCustomplot时有如题的错误 1>c:\program files (x86)\microsoft visual studio11.0\vc\include\xutility(21 ...

  9. How to install Maven on Windows

    To install Apache Maven on Windows, you just need to download the Maven’s zip file, and Unzip it to ...

  10. ubuntu upgrade

    升级命令 虽然 apt-get 经常被人诟病,但实际上它还是个挺好用的软件包管理器.在 Ubuntu 14.04 以后的系统中,apt-get 相关的升级更新命令有四个: apt-get update ...