1. charAt();如果想获取字符编码,则:charCodeAt();

var stringValue ="hello world";
alert(stringValue.charAt(4);//"o"

2. 字符串操作:concat(),可接受任意参数和“+”类似.

3. 字符串操作:slice(), substr(), substring();

  a.slice()和substring()的第二个参数指字符串的位置,而substr()第二个参数是指从第一个参数位置开始的个数.

  b.参数是负值的情况下:

    ⒈slice()方法会将传入的负值与字符串长度相加.

    ⒉substr()方法将负的第一个参数加上字符串长度,第二个参数转换成0.

    ⒊substring()方法会把所有负值参数都转换为0.

var stringValue = "hello world";
alert(stringValue.slice(-3)); //rld, -3+11
alert(stringValue.substring(-3)); //hello world, -3=>0
alert(stringValue.substr(-3)); // rld, -3+11
alert(stringValue.slice(3,-4)); // lo w, (3, -4+11)
alert(stringValue.substring(3,-4)); //"", (3,0)

4, indexOf, lastIndexOf

var stringValue ="hello world";
alert(stringValue.indexOf(“o”,6)); //7, 忽略开始的6个字符个数.
alert(stringValue,lastIndexOf("o",6));//4,忽略结束的字符个数.

5. trim(), IE9+.

6. toLowerCase(), toUpperCase(), toLocalLowerCase(), toLocalUpperCase().

7. match,类似RegExp的exec()方法. var stringValue="bat,cat"; var patter=/.at/; stringvalue.match(patter);

8. Search(). 类似match(), 返回字符串的索引项,没有返回-1.

9. Replace(), //replace("aa","bb"), 替换所有,replace(/aa/g,bb);

10. encodeURI()和encodeURIComponent().

var uri = "http://www.xx.com/illegal value.html#start";
alert(encodeURI(uri));// http://www.xx.com/illegal%20value.html#start
alert(encodeURIComponent(uri));//http%3A%2F%2F.............

11. Math.max.apply(Math,[1,2,3,4,5,6]);

  Math.Ceil() 执行向上舍入,math.ceil(25.9)=>26, math.ceil(25.5)=>26, math.ceil(25.1)=>26

  Math.floor() 执行向下舍入. math.floor(25.1)=>25, math.floor(25.5)=>

  Math.round() 执行标准舍入,

JS的string操作的更多相关文章

  1. js的日期操作:String转date日期格式、求日期差

    一.在js中String类型转成date格式 var date = new Date("2018-9-21 14:58:43");//就是这么简单 二.date转String类型就 ...

  2. js数组的操作及数组与字符串的相互转化

    数组与字符串的相互转化 <script type="text/javascript">var obj="new1abcdefg".replace(/ ...

  3. touch.js——常见应用操作

    touch.js--常见应用操作 基本事件: touchstart   //手指刚接触屏幕时触发 touchmove    //手指在屏幕上移动时触发 touchend     //手指从屏幕上移开时 ...

  4. [转]Node.JS使用Sequelize操作MySQL

    Sequelize官方文档  https://sequelize.readthedocs.io/en/latest/ 本文转自:https://www.jianshu.com/p/797e10fe23 ...

  5. js 数组的操作

    js数组的操作 用 js有很久了,但都没有深究过js的数组形式.偶尔用用也就是简单的string.split(char).这段时间做的一个项目,用到数组的地方很多,自以为js高手的自己居然无从下手,一 ...

  6. js导读,js引入,js选择器,事件,操作页面文档,计算后样式,数据类型

    js导读 ''' js属于编写运行在浏览器上的脚本语言 js采用ECMAScript语法 操作BOM:浏览器对象模型 eg:浏览器上下滑动,浏览器历史记录 操作DOM:文档对象模型 ''' js引入 ...

  7. js数组的操作 Full

    js数组的操作 用 js有很久了,但都没有深究过js的数组形式.偶尔用用也就是简单的string.split(char).这段时间做的一个项目,用到数组的地方很多,自以为js高手的自己居然无从下手,一 ...

  8. js 的数组怎么push一个对象. Js数组的操作push,pop,shift,unshift JavaScrip

    push()函数用于向当前数组的添加一个或多个元素,并返回新的数组长度.新的元素将会依次添加到数组的末尾. 该函数属于Array对象,所有主流浏览器均支持该函数. 语法 array.push( ite ...

  9. js的dom操作(整理)(转)

    js的dom操作整理(整理)(转) 一.总结 一句话总结: dom操作有用原生js的dom操作,也可以用对js封装过的jquery等插件来来更加方便的进行dom操作 1.dom是什么? 对于JavaS ...

随机推荐

  1. PyQt5开发环境搭建

    一 写在开头1.1 本节内容开个新坑—“PyQt5系列”,慢慢填.本文主要内容为PyQt5开发环境的搭建. 注意:PyQt 5.10以上的版本在Python 3.6中有BUG,PyQt 5.10版本是 ...

  2. 第十五节:深入理解async和await的作用及各种适用场景和用法

    一. 同步VS异步 1.   同步 VS 异步 VS 多线程 同步方法:调用时需要等待返回结果,才可以继续往下执行业务 异步方法:调用时无须等待返回结果,可以继续往下执行业务 开启新线程:在主线程之外 ...

  3. [Everyday Mathematics]20150306

    在王高雄等<常微分方程(第三版)>习题 2.5 第 1 题第 (32) 小题: $$\bex \frac{\rd y}{\rd x}+\frac{1+xy^3}{1+x^3y}=0. \e ...

  4. JAVA写JSON的三种方法,java对象转json数据

    JAVA写JSON的三种方法,java对象转json数据 转自:http://www.xdx97.com/#/single?bid=5afe2ff9-8cd1-67cf-e7bc-437b74c07a ...

  5. Kaldi nnet3的前向计算

    根据任务,构建ComputationRequst 编译ComputationRequst,获取NnetComputation std::shared_ptr<const NnetComputat ...

  6. ve2.0 v-for循环报错的解决方案

    <li v-for="(item,index) in mokeData" class="page" :key="index"> ...

  7. day 15 - 1 内置函数

    内置函数 作用域相关 locals() globals() #这两组开始容易搞混 print(locals()) #返回本地作用域中的所有名字 print(globals()) #返回全局作用域中的所 ...

  8. day 13 - 1 迭代器

    迭代器 首先我们查看下列类型拥有的所有方法(会显示很多) print(dir([])) print(dir({})) print(dir('')) print(dir(range(10))) #求下上 ...

  9. 第六节,Python的科学计算包——Numpy

    1.基本类型(array) import numpy as np a=[1,2,3,4] b=np.array(a) #array([1,2,3.4]) type(b) #<type 'nump ...

  10. Selenium Locating Elements

    Locating Elements Location Methods: find_element_by_id find_element_by_name find_element_by_xpath fi ...