indexOf charAt split substring substr字符串和Math常用方法总结
2016-06-24 12:12
309 查看
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>string</title> </head> <body> <script> var str = 'I love JavaScript'; //输出指定的字母,空格也算一个字符。 console.log(str.charAt(2)) //检索某个字符串首次出现的位置,如果不存在返回-1; console.log(str.indexOf('o')); console.log(str.indexOf('x')); //第一个参数是必须的,第二个是非必须的,数字代表检索的位置 console.log(str.indexOf('m',5)) //切割字符串,分割为字符串数组 //字母a当做界限。分割为数组 console.log(str.split('a')); //alert(str.split('a')) //第二个参数是可选的,显示的是分隔的次数,也就是显示的元素个数 console.log(str.split('a',2)) //提取指定下标的字符串,参数必须是非负整数 console.log(str.substring(6)) //第二个参数可选,就是取之间的字符串 console.log(str.substring(6,8)) //参数可以是负数,也可以是正数,负数的话是从后往前截取的字符个数 console.log(str.substr(-3)) //第二个参数是正数是截取字符串长度 console.log(str.substr(-3,2)) console.log(str.substr(7,4)) </script> </body> </html>
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Math</title> </head> <body> <script> //Math可以直接使用 //Math.ceil直接向上取整,就是生成的正数是比它大的正数 console.log(Math.ceil(0.8)) console.log(Math.ceil(-0.4)) //向下取整 console.log(Math.floor(0.8)) console.log(Math.floor(-0.8)) //round四舍五入 console.log(Math.round(0.4)); console.log(Math.round(-0.6)) //大于等于0但小于1 console.log(Math.random()) </script> </body> </html>
相关文章推荐
- Unable to execute dex: Multiple dex files define 错误解决方法
- 玩法更年轻,功能更创新------直播领域缘何杀出一匹黑马?
- nginx介绍(三) 配置篇
- python的subprocess模块使用方法
- 编程之美2.13子数组的最大乘积Java版
- linux常用命令总结
- 别被扩展系统ID迷惑了
- 工厂模式
- 教程
- js 锚点 不跳转
- ModelAndView 和 Model ModelMap 返回值区别
- Java基础之LinkedList
- nginx介绍(二) 架构篇
- 江苏风灾已造成98人死800人伤,默哀
- PostgreSQL数据库服务端监听设置及客户端连接方法教程
- Claims Based Authentication and Token Based Authentication和WIF
- freeswitch 1.4
- fileupload is not a function 上传错误
- 神奇的数字“9”
- 最长上升子序列