JavaScript复习之内置对象,JSON
内置对象
String对象
基础介绍
length:长度
indexOf():指定字符在字符串中第一次出现的位置
lastIndexOf():指定字符在字符串中最后一次出现的位置
substring():截取字符串
一个参数:截取到末尾
两个参数:含头不含尾
substr(m,n):截取字符串
两个参数:从索引为m开始,截取n个
split():拆分字符串
案例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
var content = 'We are family are we!!!';
console.log(content.length);
console.log(content.indexOf('a'));
console.log(content.lastIndexOf('a'));
console.log(content.substring(3));
console.log(content.substring(4, 8));
console.log(content.substr(4, 8));
console.log(content.toUpperCase());
console.log(content.toLowerCase());
var str = 'id:1,name:tom,age:18';
console.log(str.split(',')[1].split(':')[1]);
</script>
</html>
Math对象
基础介绍
ceil():向上取整
floor():向下取整