1

I was trying to create a nested list or multidimensional array where a key may have multiple values and I want to access only one particular value of that key's values.

void main()
{

  var family = {"Nabi": "Delowar", "Zerin" : ["Taheem", "Ayan"], "Nipa" : "Faizan"};

  print(family['Zerin[0]']); // this doesn't work

  print(family['Zerin']); // this prints ["Taheem", "Ayan"]

}

I want the output of Zerin[0] to be Taheem

2 Answers 2

2

First get the array from the Map with key 'Zerin' then get the item at index 0

print(family['Zerin'][0]); 
Sign up to request clarification or add additional context in comments.

4 Comments

var dd =family['Zerin']; print(dd[0]); // not working // The following works for(String d in dd) { print(d); }
got it. without using var dd = ... I need to use List dd = ...
It should work when you run it, it's just that static analysis can't know it's a List.
neither did i know. So, I ran print(dd.runtimeType); to find out
1

Try This

for (var key in family.keys) {
    print(key); // "Nabi", "Zerin", "Nipa"
}

for (var value in family.values) {
    print(value); // "Delowar", ["Taheem", "Ayan"], "Faizan"
}

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.