How to solve the error when converting Json to Map?

  • 0
    Good evening.
    I have a json like this.
    {"task_server_response":"lang_info","langs":[{"name":"Арабский","code":"ar"},{"name":"Немецкий","code":"de"},{"name":"Английский","code":"en"},{"name":"Французский","code":"fr"},{"name":"Русский","code":"ru"},{"name":"Украинский","code":"uk"},{"name":"Китайский (упрощенный)","code":"zh-cn"},{"name":"Китайский (традиционный)","code":"zh-tw"}],"pairs":[{"first":"ar","second":"ru"},{"first":"de","second":"ru"},{"first":"en","second":"ru"},{"first":"fr","second":"ru"},{"first":"ru","second":"uk"},{"first":"ru","second":"ar"},{"first":"ru","second":"zh-tw"},{"first":"ru","second":"en"},{"first":"ru","second":"fr"},{"first":"ru","second":"zh-cn"},{"first":"ru","second":"de"},{"first":"uk","second":"ru"},{"first":"zh-cn","second":"ru"},{"first":"zh-tw","second":"ru"}]}


    I'm trying to convert it to MAP like this
    let languagesCode = new Map(Object.keys(a.pairs).map(x=>[a.pairs[x].first, a.pairs[x].second]))
      console.log(languagesCode)


    Only the first eight items are printed to the console. The rest is not there, what is the mistake?
    JavaScript Declan Navarro, Jul 30, 2020

  • 1 Answers
  • 0
    There are no mistakes, everything is correct, as it should be. How many unique keys there are - as many entries in the map are created. How can multiple values ​​be accessed on a single key? It’s absurd. Obviously, you don't really know what you want to do.
    Lukas Hart

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!