ES6数组扩展(nodeList转数组)、对象扩展(对象合并)、延展操作符(字符串转数组)

35 篇文章 0 订阅
9 篇文章 0 订阅

案例代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>内置对象扩展</title>
	</head>
	<body>
		<ul>
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			<li>5</li>
			<li>6</li>
		</ul>
		<script type="text/javascript" src="js/jquery.js" ></script>
		<script>
			//1.模板字符串
			let html_1='<html><head></head><body><p>今天天气很好!</p><div>适合敲代码</div></body></html>';
			console.log(html_1);
			let str_1='今天天气很好!';
			let str_2='适合敲代码';
			let className='test';
			let html_2=`
				<html>
					<head></head>
					<body>
						<p>${str_1}</p>
						<div class="${className}">${str_2}</div>
					</body>
				</html>
			`;
			console.log(html_2);
			//2.数组的扩展
			let allLis=document.querySelectorAll('li');
			console.log(allLis);
			console.log(Array.isArray(allLis));
			//转成标准数组
			console.log(Array.from(allLis));
			console.log(Array.isArray(Array.from(allLis)));
			//字符串转数组
			console.log(Array.of(1,2,3,4));
			//3.对象扩展
			let obj={
				'name':'大金',
				'age':18
			}
			console.log(obj);
			let obj_1={'name':'小金'};
			let obj_2={'age':17};
			console.log(Object.assign(obj_1,obj_2));
			//4.延展操作符
			let name='今天天气真好!';
			let names=[...name];
			console.log(names);
			let myArr=[1,2,3,2,'大金',20,1,4];
			console.log(new Set(myArr));
			console.log([...new Set(myArr)]);
		</script>
	</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值