码迷,mamicode.com
首页 > Web开发 > 详细

JS indexOf(),split(),substring(),substr(),Math.ceil(),Math.floor(),Math.round()的内容

时间:2018-07-25 10:24:04      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:mys   返回   length   数字   分割   round   整数   floor   输出   

indexOf():

var mystr="Hello WorHld!"

括号内若只有一个参数,代表要查找的字符;例:document.write(mystr.indexOf("H"));

括号内若有两个参数,前一个代表要查找的字符,后一个代表从哪个位置开始查找;例:document.write(mystr.indexOf("H",7));

若要查找的字符没有,则返回-1

 

split():切割符

var mystr="86-010-85468578";

括号内若填 "-" ,则表示在"-"切割,结果为:86,010,85468578

括号内若填 "-" ,2 ,则表示在"-"切割,切两段,结果为:86,010

括号内若填 "" ,则每个字符都会被分割,结果为:8,6,-,0,1,0,-,8,5,4,6,8,5,7,8

括号内若填 "",3 ,则前三个字符都会被分割,结果为:8,6,-

 

substring():提取字符串

var mystr="Hello World!"

当substring()的括号内填 一个(数字)参数 a,则表示返回从a(包括a)开始一直到  结尾.length-1  的字符

当substring()的括号内填 两个(数字)参数  a,b ,则表示返回从a(包括a)开始一直到b的字符

 

substr():提取指定数目

var mystr="Hello World!";

当括号内填一个(数字)参数a时,表示从a(不包括a)开始一直到  结尾

当括号内填两个(数字)参数 a,b 时,表示从a开始,到后面的 b 个字符,例:document.write(mystr.substr(0,5));——输出:Hello

var mystr="Hello World!";

-1是倒数第一个字符(!),-2是倒数第二个字符(d!),依此类推

 

Math.ceil():向上取整数

例:document.write(Math.ceil(-9.9));——输出:-9

document.write(Math.ceil(-0.1));——输出:0

 

Math.floor():想下取整

例:document.write(Math.floor(-9.9));——输出:-10

document.write(Math.floor(-0.1));——输出:-1

 

Math.round():四舍五入

例:document.write(Math.round(-9.9));——输出:-10

document.write(Math.round(-0.1));——输出:0

 

JS indexOf(),split(),substring(),substr(),Math.ceil(),Math.floor(),Math.round()的内容

标签:mys   返回   length   数字   分割   round   整数   floor   输出   

原文地址:https://www.cnblogs.com/chenyuan7/p/9164946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!