admin管理员组文章数量:1026989
I try to get the id's from List of Maps in Dart. In JavaScript it would be something like this:
var list = [{id:3, name:'third'}, {id:4, name:'fourth'}];
var result = list.map(function(x){return x.id;});
This should give the result
[3, 4]
Is there a simple way of doing this in Dart?
So far I was able to do this (in Dart):
var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']);
The result is a "MappedListIterable" (not sure what that is) and you cannot use result[0]
like you can with a normal List. How can I make a list of this?
I try to get the id's from List of Maps in Dart. In JavaScript it would be something like this:
var list = [{id:3, name:'third'}, {id:4, name:'fourth'}];
var result = list.map(function(x){return x.id;});
This should give the result
[3, 4]
Is there a simple way of doing this in Dart?
So far I was able to do this (in Dart):
var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']);
The result is a "MappedListIterable" (not sure what that is) and you cannot use result[0]
like you can with a normal List. How can I make a list of this?
1 Answer
Reset to default 8See the API for List.map and the API for Iterable (which it returns). You can get the n
th element from the iterable using .elementAt(n)
or the first element using .first
.
var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']).first;
You can also turn it back into a List
using .toList()
:
var resultList = list.map((x) => x['id']).toList();
I try to get the id's from List of Maps in Dart. In JavaScript it would be something like this:
var list = [{id:3, name:'third'}, {id:4, name:'fourth'}];
var result = list.map(function(x){return x.id;});
This should give the result
[3, 4]
Is there a simple way of doing this in Dart?
So far I was able to do this (in Dart):
var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']);
The result is a "MappedListIterable" (not sure what that is) and you cannot use result[0]
like you can with a normal List. How can I make a list of this?
I try to get the id's from List of Maps in Dart. In JavaScript it would be something like this:
var list = [{id:3, name:'third'}, {id:4, name:'fourth'}];
var result = list.map(function(x){return x.id;});
This should give the result
[3, 4]
Is there a simple way of doing this in Dart?
So far I was able to do this (in Dart):
var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']);
The result is a "MappedListIterable" (not sure what that is) and you cannot use result[0]
like you can with a normal List. How can I make a list of this?
1 Answer
Reset to default 8See the API for List.map and the API for Iterable (which it returns). You can get the n
th element from the iterable using .elementAt(n)
or the first element using .first
.
var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']).first;
You can also turn it back into a List
using .toList()
:
var resultList = list.map((x) => x['id']).toList();
本文标签: javascriptDart equivalent of Arrayprototypemap()Stack Overflow
版权声明:本文标题:javascript - Dart equivalent of Array.prototype.map()? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745669303a2162363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论