案例代码:
<!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>