<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>取原始数组中的指定数据push新数组</title>
</head>
<body>
<script>
const arr = [
{
name: 'swk',
age: 24,
height: 1.99,
address: 'hgs'
},
{
name: 'zbj',
age: 22,
height: 1.99,
address: 'hgs'
},
{
name: 'shs',
age: 26,
height: 1.99,
address: 'hgs'
},
{
name: 'tsz',
age: 30,
height: 1.99,
address: 'hgs'
}
]
const newArr = []
arr.forEach(item => {
newArr.push([item.name, item.age])
})
console.log(newArr)
</script>
</body>
</html>
2.将原数组中每一项的barcode重新push到一个新数组中,使用map
const arr = [
{
barcode: {
name: "swk",
age: 24,
height: 1.99,
address: "hgs",
},
used: false,
pid: 123,
w: "123",
groopName: "xx",
},
];
const newArr = [];
arr.map((item) => {
newArr.push(item.barcode);
});
console.log(newArr)
newArr
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/79203.html