[英]how to get specific json data from http response
In my application i am getting data from a http request.在我的应用程序中,我从 http 请求中获取数据。 in my http response i have json array with 500 values.
在我的 http 响应中,我有 500 个值的 json 数组。 each index of an array has 10 values.
数组的每个索引都有 10 个值。 i am trying to get specific value for each index in the array and push it inot another arry.
我正在尝试获取数组中每个索引的特定值并将其推送到另一个数组中。 what is the best way of doing it.
最好的方法是什么。
constructor(private test: TestService){
this.test.getdata().subscribe(data => {console.log(data);})
}
data = [{t1: 20, t2: 30, tt4: 50, t6:60...t10:100},
{t1: 600, t2: 30, tt4: 50, t6:60...t10:100},
{t1: 200, t2: 30, tt4: 50, t6:60...t10:100}
]
// my new array should look like this. it should contain only the values of t1 for each index.
arr = [20, 600, 200]
You may need map
here:您可能需要
map
:
var data = [{t1: 20, t2: 30, tt4: 50, t6:60}, {t1: 600, t2: 30, tt4: 50, t6:60}, {t1: 200, t2: 30, tt4: 50, t6:60}]; var result = data.map(({t1})=>t1); console.log(result);
Try this..尝试这个..
var arr = [];
this.data.map((item) => {
this.arr.push(item.t1);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.