2

I have a List in the following format:

List<ImageCollections> collectionlist;

It looks like this:

collectionlist = [
  { collectionname: 'abc', srcimage: url1, collectionimgnumber: 5, hreflink: link1 },
  { collectionname: 'xyz', srcimage: url2, collectionimgnumber: 4, hreflink: link2 },
  ...
];

Is there a way I can create a new List containing only the srcimage of each entry?

The new list should look like this:

newList = [ url1, url2, ... ];

2 Answers 2

3

You can use Iterable.map:

newList = collectionlist.map((object) => object.srcimage);
Sign up to request clarification or add additional context in comments.

2 Comments

how can i take both values collectionname and srcimage
@HitanshuGogoi (object) => { 'srcimage': object.srcimage, 'collectionname': object.collectionname }
1

Use the list map function:

srcimagelist = collectionlist.map((x) => x.srcimage);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.