JavaScript复习之内置对象,JSON

这篇博客主要复习了JavaScript中的内置对象,包括String、Math、Array和Date对象的基础介绍及应用案例。此外,还详细讲解了JSON的基础知识和使用示例。
摘要由CSDN通过智能技术生成

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>
		/* 
			String对象:
				length:长度
				indexOf():指定字符在字符串中第一次出现的位置
				lastIndexOf():指定字符在字符串中最后一次出现的位置
				substring():截取字符串
					一个参数:截取到末尾
					两个参数:含头不含尾
				substr(m,n):截取字符串
					两个参数:从索引为m开始,截取n个
				split():拆分字符串
						
		 */
		var content = 'We are family are we!!!';
		console.log(content.length); //23
		console.log(content.indexOf('a')); //3
		console.log(content.lastIndexOf('a')); //14
		console.log(content.substring(3)); //are family are we!!!
		console.log(content.substring(4, 8)); //re f
		console.log(content.substr(4, 8)); // re famil
		console.log(content.toUpperCase()); // 全大写
		console.log(content.toLowerCase()); // 全小写
		var str = 'id:1,name:tom,age:18';
		// 获取tom
		console.log(str.split(',')[1].split(':')[1]); //tom
	</script>
</html>

Math对象

基础介绍
ceil():向上取整
floor():向下取整
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值