<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 将对象转换为二维数组
const list = [
{ 'name': "张三", 'age': 17, 'sex': "男", 'hobby': "写代码" },
{ 'name': "李四", 'age': 18, 'sex': "男", 'hobby': "看书" },
{ 'name': "王五", 'age': 15, 'sex': "男", 'hobby': "打游戏" },
{ 'name': "小明", 'age': 20, 'sex': "男", 'hobby': "学习" },
{ 'name': "小红", 'age': 24, 'sex': "女", 'hobby': "追剧" },
]
function formatJson(list) {
// 遍历每一个对象
const arr = list.map(item => {
for(key in item) return item
})
console.log(arr);
}
formatJson(list)
</script>
</body>
</html>
本文链接:https://liuyuyang.net/index.php/archives/1858/
2022年10月25日 11:22
你的技术 我的梦!