老师,是这样写吗
来源:2-11 编程练习
廖可爱bongbong
2021-06-24 11:59:41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let str = "study hard and make and progress every day study"
// 在此补充代码
//将字符串转换为数组
const a =str.split(' ');
//将数组作为参数传入Set中
const s =new Set(a);
// 使用扩展运算符在数组中展开Set,将Set转成数组
const b = [...s];
//最后再将数组转成字符串,输出到页面中
document.write(b.join(' ')+'</br>');
//一步到位:
document.write([...new Set(str.split(' '))].join(' '));
</script>
</body>
</html>
1回答
同学你好,代码实现没问题,继续加油,祝学习愉快!
相似问题