//字符中的字符从左向右进行索引,由0开始,字符串中的空格也算在内

var string = "charAt find word position";
document.write("charAt find word position"+ "<br/>")
document.write("string.charAt(0) is:" + string.charAt(0) + "<br/>");
document.write("string.charAt(1) is:" + string.charAt(1) + "<br/>");
document.write("string.charAt(2) is:" + string.charAt(2) + "<br/>");
document.write("string.charAt(3) is: " + string.charAt(3) + "<br/>");
document.write("string.charAt(4) is: " + string.charAt(4) + "<br/>");
document.write("string.charAt(5) is: " + string.charAt(5) + "<br/>");
document.write("string.charAt(6) is: " + string.charAt(6) + "<br/>");
document.write("string.charAt(7) is: " + string.charAt(7) + "<br/>");
document.write("string.charAt(string.length-2) is: " + string.charAt(string.length-2) + "<br/>")
document.write("string.charAt(string.length-1) is: " + string.charAt(string.length-1) + "<br/>") //输出结果
string.charAt(0) is:c
string.charAt(1) is:h
string.charAt(2) is:a
string.charAt(3) is: r
string.charAt(4) is: A
string.charAt(5) is: t
string.charAt(6) is: 
string.charAt(7) is: f
string.charAt(string.length-2) is: o
string.charAt(string.length-1) is: n

//返回该字符串

function findCharAt(str,n){
var obj = String(str); // 转化为字符串
var pos; //定义变量
pos = obj.charAt(n-1); //查找的索引
return pos; //返回字符
}
alert(findCharAt("这是第几个",1));

js的字符串charAt()方法的更多相关文章

  1. js中字符串的方法

    js String对象中常用方法小结,需要的朋友可以参考下: 1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: ...

  2. JS常用字符串处理方法应用总结

    这篇文章主要总结了JS常用字符串的处理方法,需要的朋友可以参考下   1.indexOf()方法,从前往后查找字符串位置,大小写敏感,从0开始计数.同理,lastIndexOf() 方法从后往前,两个 ...

  3. [JS高程] 字符串模式匹配方法

    目录 1. RegExp 对象 2. 字符串模式匹配方法 2.1 match() , search() 2.2 replace() 2.2.1 第二个参数为字符串的应用情况 2.2.2 第二个参数为函 ...

  4. js常用字符串处理方法

    JS自带函数concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = a ...

  5. JS截取字符串 charAt(),slice(),substring(),substr()

    1. charAt(i)输出指定下标的字母,长度为1,适用于把字符串切割成单个字符串. 2. slice() 和 substring() 都支持1-2个参数,第一个参数是开始位置,第二个参数是结束位置 ...

  6. js截取字符串的方法

    1,slice(a, b) 第一个参数表示起始位置,第二个表示截取到但不包含 关于参数正负问题,只要记住一点:永远不能倒着截取!否则返回空字符串 2,substring(a, b) 第一个参数表示起始 ...

  7. js 把字符串当做方法执行

    <SCRIPT LANGUAGE="JavaScript"> function test(str){ alert(str); } eval('test("aa ...

  8. JS对象 charAt() 方法可返回指定位置的字符。返回的字符是长度为 1 的字符串。

    返回指定位置的字符 charAt() 方法可返回指定位置的字符.返回的字符是长度为 1 的字符串. 语法: stringObject.charAt(index) 参数说明: 注意:1.字符串中第一个字 ...

  9. 不要再混淆js的substring和substr了!(附js所有字符串方法)

    一.字符串操作方法 js中字符串方法操作有很多:concat.indexOf.... 这里只要介绍两种经常混淆的字符串截取方法:substring.substr 二.从例子入手 let str = ' ...

随机推荐

  1. CodeIgniter(3.1.4)框架中整合ThinkPHP验证码

    下载源码包: https://github.com/top-think/think-captcha 字体库: 源文件路径: //代码中字体路径,背景路径已经修改. <?php class Vco ...

  2. ubuntu 12.04 rails server 时候报错 execjs

    新的应用创建好了,使用rails server启动看看,oops!原来是没有javascript运行环境. 1 2 $ rails server  /usr/local/lib/ruby/gems/1 ...

  3. 一个CSS3滤镜Drop-shadow阴影效果

    <html> <head> <title>CSS3 Drop-shadow阴影</title> <style type="text/cs ...

  4. ffplay的音视频同步分析

    以前工作中参与了一些音视频程序的开发,不过使用的都是芯片公司的SDK,没有研究到更深入一层,比如说音视频同步是怎么回事.只好自己抽点时间出来分析开源代码了,做音视频编解码的人都知道ffmpeg,他在各 ...

  5. linux -- Ubuntu开启root账户,并切换到root用户登陆

    启用root账户 ubuntu 的root账户具有最高的系统权限,它类似于windows系统中的管理员账号,但是比windows系统中管理员账号的权限更高,一般都情况下不要使用root账户,但是有的时 ...

  6. php一些常规动态设置与获取

    error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE);ini ...

  7. 最大子数组之和(N)

    int maxSum(int *array, int n) { ]; ; ; ; i < n; i++) { ) newsum += array[i]; else newsum = array[ ...

  8. 对于MathType中公式与文字错位的问题怎么解决

    MathType是强大的数学公式编辑器,与常见的文字处理软件和演示程序配合使用,能够在各种文档中加入复杂的数学公式和符号,可用在编辑数学试卷.书籍.报刊.论文.幻灯演示等方面,是编辑数学资料的得力工具 ...

  9. linux下mysql 启动命令

    1,使用service 启动.关闭MySQL服务 service mysql start service mysql stop service mysql restart 运行上面命令,其实是serv ...

  10. java程序后台报错java.net.SocketException: Too many open files

    问题描述: 今天一个同事反映程序有问题,让帮忙查看后台日志,发现后台日志报错的信息如下: java.net.SocketException: Too many open files at java.n ...