1. <script>
  2. var arr=[
  3. {
  4. name:"lisi",
  5. age:18,
  6. likes:["lol","足球"],
  7. alikes:["asd","fs"],
  8. sex:"male"
  9. },
  10. {
  11. name:"占山",
  12. age:18,
  13. likes:["合法化","足球"],
  14. alikes:["asd","回复"],
  15. sex:"male"
  16. },
  17. {
  18. name:"请问请问",
  19. age:18,
  20. likes:["lol","破解"],
  21. alikes:["asd","fs"],
  22. sex:"male"
  23. }
  24. ]
  25. var res = [];
  26. for(var i=0;i<arr.length;i++){
  27. // 解构
  28. var {name,age,likes,alikes} = arr[i];
  29. // 展开
  30. likes.push(...alikes);
  31. // 键值相同 只写一个
  32. var obj = {
  33. name,
  34. age,
  35. likes,
  36. }
  37. res.push(obj)
  38. }
  39. console.log(res)
  40. </script>

版本2

  1. <script>
  2. var arr=[
  3. {
  4. name:"lisi",
  5. age:18,
  6. likes:["lol","足球"],
  7. alikes:["asd","fs"],
  8. sex:"male"
  9. },
  10. {
  11. name:"占山",
  12. age:18,
  13. likes:["合法化","足球"],
  14. alikes:["asd","回复"],
  15. sex:"male"
  16. },
  17. {
  18. name:"请问请问",
  19. age:18,
  20. likes:["lol","破解"],
  21. alikes:["asd","fs"],
  22. sex:"male"
  23. }
  24. ]
  25. var res = [];
  26. for(var i=0;i<arr.length;i++){
  27. // 解构
  28. var {name,age,likes,alikes} = arr[i];
  29. // 展开
  30. likes.push(...alikes);
  31. // 键值相同 只写一个
  32. var obj = {
  33. name,
  34. age,
  35. likes,
  36. }
  37. res.push(obj)
  38. }
  39. console.log(res)
  40. </script>