码迷,mamicode.com
首页 > 编程语言 > 详细

JS 过滤数组里对象的某个属性

时间:2019-09-10 17:46:55      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:dev   har   push   数组   type   ati   pre   init   console   

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5     <meta charset="UTF-8">
 6     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 8     <title>Document</title>
 9 </head>
10 
11 <body>
12 
13     <script>
14         var newArray = [{
15                 name: "aaa",
16                 value: 0,
17                 height: 1
18             },
19             {
20                 name: "ddd",
21                 value: 3,
22                 height: 1
23             },
24             {
25                 name: "bbb",
26                 value: 1,
27                 height: 1
28             },
29             {
30                 name: "eee",
31                 value: 4,
32                 height: 1
33             },
34             {
35                 name: "ccc",
36                 value: 2,
37                 height: 1
38             }
39         ];
40 
41 
42         var newArray2 = [];
43         for (var i = 0; i < newArray.length; i++) {
44             var newObject = {};
45             newObject.name = newArray[i].name;
46             newObject.height = newArray[i].value;
47             newArray2.push(newObject);
48         }
49         console.log(newArray2)
50 
51 
52         // for (var i = 0; i < 6; i++) {
53         //     setTimeout(function () {
54         //         console.log(i);
55         //     }, 0)
56         // }
57     </script>
58 
59 </body>
60 
61 </html>

 

JS 过滤数组里对象的某个属性

标签:dev   har   push   数组   type   ati   pre   init   console   

原文地址:https://www.cnblogs.com/rongyao/p/11498636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!