学习内容:
1、 数组或者对象合并(深拷贝)
2、 数组或者对象解构
3、 map()方法的使用
数组合并(深拷贝):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
let arr = ['a','b','c']
let arr2 = ['11','22','33']
console.log(arr)
console.log(arr2)
arr3 = [...arr2,...arr]//数组合并,深拷贝
console.log(arr3)
</script>
</html>
效果图:
解构:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
const book = [
{name:'java',price:'29'},
{name:'js',price:'19'},
{name:'c',price:'9.9'}
]
const [a,b,c] = book//解构出a,b,c三个对象
console.log(a)
console.log(b)
console.log(c)
</script>
</html>
效果图:
map()的使用:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
const book = [
{name:'java',price:'29'},
{name:'js',price:'19'},
{name:'c',price:'9.9'}
]
book.map((item) => {
console.log('书名:'+item.name+'的价格为:'+item.price+'元')
})
</script>
</html>