- 原生html、JavaScript、css实现表格(考察JavaScript基本操作),如下图:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/dae7fc5cb5698d3186a1ad54f5b557e6.png#pic_center)
<!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>
<style>
.title-wrap {
font-size: 32px;
font-weight: bold;
color: #333333;
display: flex;
flex-direction: row;
justify-content: space-between;
height: 100px;
line-height: 100px;
text-align: center;
border: 1px solid #dddddd;
}
.title-wrap span {
width: 20%;
display: inline-block;
border-left: 1px solid #dddddd;
}
#list div {
display: flex;
flex-direction: row;
text-align: center;
border: 1px solid #dddddd;
border-top: none;
}
#list div span {
display: block;
width: 20%;
height: 50px;
line-height: 50px;
border-left: 1px solid #dddddd;
}
</style>
<body>
<div class="content">
<div class="title-wrap">
<span>日期</span><span>省份</span><span>市区</span><span>地址</span
><span>邮箱</span>
</div>
<div id="list"></div>
</div>
</body>
<script>
let lists = [
{
date: '2016-05-03',
pro: '上海',
shi_qu: '普陀区',
ard: '上海',
you_bian: '299333',
},
{
date: '2016-05-03',
pro: '上海',
shi_qu: '普陀区',
ard: '上海',
you_bian: '299333',
},
{
date: '2016-05-03',
pro: '上海',
shi_qu: '普陀区',
ard: '上海',
you_bian: '299333',
},
]
let dom_1 = document.getElementById('list')
for (const item of lists) {
let dom = document.createElement('div')
for (const key in item) {
let dom_2 = document.createElement('span')
let node_text = document.createTextNode(item[key])
dom_2.appendChild(node_text)
dom.appendChild(dom_2)
}
dom_1.appendChild(dom)
}
</script>
</html>
- 多维数组转为一维数组(或许是我太low了,这样写不是很快吗)
function flat(arr) {
let str = JSON.stringify(arr).replace(/\[|\]/g, '')
console.log(str.split(','))
}
let arr = [0, [1, 2], [3, [4, 5]], [6, [7, [8, 9, [10]]]]]
flat(arr)
- 深拷贝:递归(算法、引用类型、基本类型)
function deepClone(obj) {
let obj_1 = {};
if (Object.prototype.toString.call(obj) !== '[object Object]') {
return -1
}
for (let key in obj) {
if (Object.prototype.toString.call(obj[key]) === '[object Object]') {
obj_1[key] == deepClone(obj[key]);
} else {
obj_1[key] = obj[key];
}
}
return obj_1;
}