search in maps dart2 , same as list.indexOf?


I Use this sample for search in Map but not work :|:

  var xmenList = ['4','xmen','4xmen','test'];
  var xmenObj = {
  'first': '4',
  'second': 'xmen',
  'fifth': '4xmen',
   'author': 'test'

  print(xmenList.indexOf('4xmen')); // 2
  print(xmenObj.indexOf('4xmen')); // ?

but I have error TypeError: xmenObj.indexOf$1 is not a function on last code line.

Pelease help me to search in map object simple way same as indexOf.


I found the answer:

 print(xmenObj.values.toList().indexOf('4xmen')); // 2

or this:

  var ind = xmenObj.values.toList().indexOf('4xmen') ;
  print(xmenObj.keys.toList()[ind]); // fifth

Answered By – A1Gard

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *