在js中怎样将一个对象的的部分属性取出来
1 <script> 2 var json = { 3 "code": 200, 4 "data": { 5 "rows": [ 6 { 7 "code": "system", 8 "creatName": "系统管理员", 9 "createBy": 1, 10 "createDate": "2019-09-11 16:28:27", 11 "deptId": "", 12 "deptName": "顶级机构", 13 "description": "所有权限", 14 "id": 1, 15 "name": "平台超级管理员", 16 "orderNo": 1, 17 "osCode": "rbac", 18 "stateName": "启用", 19 "status": 0, 20 "updateBy": 1, 21 "updateDate": "2019-09-11 16:28:27", 22 "updateName": "系统管理员" 23 }, 24 { 25 "code": "16", 26 "creatName": "系统管理员", 27 "createBy": 1, 28 "createDate": "2019-09-11 16:28:27", 29 "deptId": "", 30 "deptName": "天恒", 31 "description": "天恒", 32 "id": 7, 33 "name": "天恒角色", 34 "orderNo": 2, 35 "osCode": "", 36 "stateName": "启用", 37 "status": 0, 38 "updateBy": 1, 39 "updateDate": "2019-09-11 16:28:27", 40 "updateName": "系统管理员" 41 }, 42 { 43 "code": "17", 44 "creatName": "系统管理员", 45 "createBy": 1, 46 "createDate": "2019-09-19 13:50:11", 47 "deptId": "", 48 "deptName": "研究院", 49 "description": "研发研发", 50 "id": 5907, 51 "name": "研发研发", 52 "orderNo": 100, 53 "osCode": "", 54 "stateName": "启用", 55 "status": 0, 56 "updateBy": 1, 57 "updateDate": "2019-09-19 13:53:03", 58 "updateName": "系统管理员" 59 }, 60 { 61 "code": "system", 62 "creatName": "系统管理员", 63 "createBy": 1, 64 "createDate": "2019-09-23 15:27:30", 65 "deptId": "", 66 "deptName": "顶级机构", 67 "description": "", 68 "id": 5908, 69 "name": "顶级机构", 70 "orderNo": 100, 71 "osCode": "", 72 "stateName": "启用", 73 "status": 0, 74 "updateBy": 1, 75 "updateDate": "2019-09-25 14:45:32", 76 "updateName": "系统管理员" 77 } 78 ], 79 "total": "4" 80 }, 81 "message": "", 82 "page": "" 83 } 84 var arr = json.data.rows; 85 var result = []; //定义一个数组 86 for(var i = 0; i < arr.length; i++) { 87 var obj = arr[i]; 88 console.log(obj) // arr[i] 分别是每个对象 89 result.push({ 90 "id":obj.id, 91 "name":obj.name, 92 }) //将对象push到数组中 93 } 94 console.log(result); 95 96 </script>