2017-02-23 51 views
-5

我有以下的JSON,我想提取唯一的位置,并把它放在另一个JSON或数组中与以前相同的格式。我是一个新手,因此,对我来说有点困惑。如何从Angular的JSON数据中提取特定的键?

这是我有:

let data = { 
    "Person" : [{"name":"harman","comment_count":255}, 
       {"name":"aman","comment_count":66}, 
       {"name":"mukesh","comment_count":66}], 
    "location": [{"name":"delhi","comment_count":255}, 
       {"name":"mumbai","comment_count":66}, 
       {"name":"chandigarh","comment_count":66}], 
    "org  ": [{"name":"dell","comment_count":255}, 
       {"name":"apple","comment_count":66}, 
       {"name":"hp","comment_count":66}], 
    "teams" : [{"name":"Real","comment_count":255}, 
       {"name":"Juve","comment_count":66}, 
       {"name":"Liverpool","comment_count":66}]   
}; 

这就是我想要的:

data2 = { 
    "location": [ 
     {"name":"delhi","comment_count":255}, 
     {"name":"mumbai","comment_count":66}, 
     {"name":"chandigarh","comment_count":66}]  
}; 
+0

非常基本的东西 –

+1

'data2.location = data.location;' –

回答

1

做到这一点。

data2 = data.location 
2

包括下面的代码片段。只需使用var data2 = data.location;好运


 
    window.onload = function(){ 
 
    
 
     let data = { 
 
         "Person" : [{"name":"harman","comment_count":255}, 
 
            {"name":"aman","comment_count":66}, 
 
            {"name":"mukesh","comment_count":66}], 
 
         "location": [{"name":"delhi","comment_count":255}, 
 
            {"name":"mumbai","comment_count":66}, 
 
            {"name":"chandigarh","comment_count":66}], 
 
         "org  ": [{"name":"dell","comment_count":255}, 
 
            {"name":"apple","comment_count":66}, 
 
            {"name":"hp","comment_count":66}], 
 
         "teams" : [{"name":"Real","comment_count":255}, 
 
            {"name":"Juve","comment_count":66}, 
 
            {"name":"Liverpool","comment_count":66}]   
 
     }; 
 
     
 
     var data2 = data.location; 
 
     console.log("data2:"); 
 
     console.log(data2); 
 
    
 
    };