JavaScript怎么把两个数组里的多个对象一一对应合并?

2020-04-14  本文已影响0人  前端Tree
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
    <script>
        var arr = [{
            name : "张三",
            age : '132',
        },{
            name : "张三1",
            age : '13222',
        }]
        var arr1 = [
            {
                play : "打球",
                eat:"吃饭"
            },
            {
                play : "打球1",
                eat:"吃饭2"
            }
        ]
        obj = arr.map((item,index) => {
            return {...item, ...arr1[index]};
        });
        console.log('item',obj)
    </script>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读