1. <script>
  2. // 针对json对象
  3. /* tips:只能获取对象中的第一层属性 */
  4. var obj ={
  5. name:"lisi",
  6. age:19,
  7. likes:{
  8. a:10
  9. }
  10. }
  11. var {name,age,likes} = obj;
  12. console.log(likes)
  13. </script>

例子

  1. <script>
  2. var arr = [{
  3. name: "lisi",
  4. age: 18,
  5. likes: ["lol", "足球"],
  6. alikes: ["音乐", "电影"],
  7. sex: "male"
  8. },
  9. {
  10. name: "王五",
  11. age: 17,
  12. likes: ["al", "栏球"],
  13. alikes: ["防抖", "放到"],
  14. sex: "male"
  15. },
  16. {
  17. name: "张三",
  18. age: 165,
  19. likes: ["发顺丰", "jf"],
  20. alikes: ["音乐9", "10电影"],
  21. sex: "male"
  22. }
  23. ]
  24. /*
  25. [{
  26. name:"张三",
  27. age:165,
  28. likes:["发顺丰","jf","音乐9","10电影"],
  29. }]
  30. */
  31. var res = [];
  32. for(var i=0;i<arr.length;i++){
  33. var {name,age,likes,alikes} = arr[i];
  34. likes.push(...alikes);
  35. res.push({
  36. name,
  37. age,
  38. likes
  39. })
  40. }
  41. console.log(res);
  42. </script>