title: how to flat the object values in javascript
body: <p>i need to flat the object values in javascript . the ent is the input array . the first object the language  consist of array of array values i need to flat the object value .[[{}],[{}],[{}]]</p>
  <p>experted the value to be language: [{},{},{}];</p>
  <pre><code>
  
  
  const ent =[{
      &quot;name&quot;: &quot;Afghanistan&quot;,
      &quot;topLevelDomain&quot;: [
        &quot;.af&quot;
      ],
      &quot;alpha2Code&quot;: &quot;AF&quot;,
      &quot;alpha3Code&quot;: &quot;AFG&quot;,
      &quot;callingCodes&quot;: [
        &quot;93&quot;
      ],
      &quot;capital&quot;: &quot;Kabul&quot;,
      &quot;altSpellings&quot;: [
        &quot;AF&quot;,
        &quot;Afġānistān&quot;
      ],
      &quot;region&quot;: &quot;Asia&quot;,
      &quot;subregion&quot;: &quot;Southern Asia&quot;,
      &quot;population&quot;: 27657145,
      &quot;latlng&quot;: [
        33,
        65
      ],
      &quot;demonym&quot;: &quot;Afghan&quot;,
      &quot;area&quot;: 652230,
      &quot;gini&quot;: 27.8,
      &quot;timezones&quot;: [
        &quot;UTC+04:30&quot;
      ],
      &quot;borders&quot;: [
        &quot;IRN&quot;,
        &quot;PAK&quot;,
        &quot;TKM&quot;,
        &quot;UZB&quot;,
        &quot;TJK&quot;,
        &quot;CHN&quot;
      ],
      &quot;nativeName&quot;: &quot;افغانستان&quot;,
      &quot;numericCode&quot;: &quot;004&quot;,
      &quot;currencies&quot;: [
        {
          &quot;code&quot;: &quot;AFN&quot;,
          &quot;name&quot;: &quot;Afghan afghani&quot;,
          &quot;symbol&quot;: &quot;؋&quot;
        }
      ],
      &quot;languages&quot;: [
        [{
          &quot;iso639_1&quot;: &quot;ps&quot;,
          &quot;iso639_2&quot;: &quot;pus&quot;,
          &quot;name&quot;: &quot;Pashto&quot;,
          &quot;nativeName&quot;: &quot;پښتو&quot;
        }],
        [{
          &quot;iso639_1&quot;: &quot;uz&quot;,
          &quot;iso639_2&quot;: &quot;uzb&quot;,
          &quot;name&quot;: &quot;Uzbek&quot;,
          &quot;nativeName&quot;: &quot;Oʻzbek&quot;
        }],
        [{
          &quot;iso639_1&quot;: &quot;tk&quot;,
          &quot;iso639_2&quot;: &quot;tuk&quot;,
          &quot;name&quot;: &quot;Turkmen&quot;,
          &quot;nativeName&quot;: &quot;Türkmen&quot;
        }],
      ],
      &quot;translations&quot;: {
        &quot;de&quot;: &quot;Afghanistan&quot;,
        &quot;es&quot;: &quot;Afganistán&quot;,
        &quot;fr&quot;: &quot;Afghanistan&quot;,
        &quot;ja&quot;: &quot;アフガニスタン&quot;,
        &quot;it&quot;: &quot;Afghanistan&quot;,
        &quot;br&quot;: &quot;Afeganistão&quot;,
        &quot;pt&quot;: &quot;Afeganistão&quot;,
        &quot;nl&quot;: &quot;Afghanistan&quot;,
        &quot;hr&quot;: &quot;Afganistan&quot;,
        &quot;fa&quot;: &quot;افغانستان&quot;
      },
      &quot;flag&quot;: &quot;https://restcountries.eu/data/afg.svg&quot;,
      &quot;regionalBlocs&quot;: [
        {
          &quot;acronym&quot;: &quot;SAARC&quot;,
          &quot;name&quot;: &quot;South Asian Association for Regional Cooperation&quot;,
          &quot;otherAcronyms&quot;: [],
          &quot;otherNames&quot;: []
        }
      ],
      &quot;cioc&quot;: &quot;AFG&quot;
    },
    {
      &quot;name&quot;: &quot;Åland Islands&quot;,
      &quot;topLevelDomain&quot;: [
        &quot;.ax&quot;
      ],
      &quot;alpha2Code&quot;: &quot;AX&quot;,
      &quot;alpha3Code&quot;: &quot;ALA&quot;,
      &quot;callingCodes&quot;: [
        &quot;358&quot;
      ],
      &quot;capital&quot;: &quot;Mariehamn&quot;,
      &quot;altSpellings&quot;: [
        &quot;AX&quot;,
        &quot;Aaland&quot;,
        &quot;Aland&quot;,
        &quot;Ahvenanmaa&quot;
      ],
      &quot;region&quot;: &quot;Europe&quot;,
      &quot;subregion&quot;: &quot;Northern Europe&quot;,
      &quot;population&quot;: 28875,
      &quot;latlng&quot;: [
        60.116667,
        19.9
      ],
      &quot;demonym&quot;: &quot;Ålandish&quot;,
      &quot;area&quot;: 1580,
      &quot;gini&quot;: null,
      &quot;timezones&quot;: [
        &quot;UTC+02:00&quot;
      ],
      &quot;borders&quot;: [],
      &quot;nativeName&quot;: &quot;Åland&quot;,
      &quot;numericCode&quot;: &quot;248&quot;,
      &quot;currencies&quot;: [
        {
          &quot;code&quot;: &quot;EUR&quot;,
          &quot;name&quot;: &quot;Euro&quot;,
          &quot;symbol&quot;: &quot;€&quot;
        }
      ],
      &quot;languages&quot;: [
        {
          &quot;iso639_1&quot;: &quot;sv&quot;,
          &quot;iso639_2&quot;: &quot;swe&quot;,
          &quot;name&quot;: &quot;Swedish&quot;,
          &quot;nativeName&quot;: &quot;svenska&quot;
        }
      ],
      &quot;translations&quot;: {
        &quot;de&quot;: &quot;Åland&quot;,
        &quot;es&quot;: &quot;Alandia&quot;,
        &quot;fr&quot;: &quot;Åland&quot;,
        &quot;ja&quot;: &quot;オーランド諸島&quot;,
        &quot;it&quot;: &quot;Isole Aland&quot;,
        &quot;br&quot;: &quot;Ilhas de Aland&quot;,
        &quot;pt&quot;: &quot;Ilhas de Aland&quot;,
        &quot;nl&quot;: &quot;Ålandeilanden&quot;,
        &quot;hr&quot;: &quot;Ålandski otoci&quot;,
        &quot;fa&quot;: &quot;جزایر الند&quot;
      },
      &quot;flag&quot;: &quot;https://restcountries.eu/data/ala.svg&quot;,
      &quot;regionalBlocs&quot;: [
        {
          &quot;acronym&quot;: &quot;EU&quot;,
          &quot;name&quot;: &quot;European Union&quot;,
          &quot;otherAcronyms&quot;: [],
          &quot;otherNames&quot;: []
        }
      ],
      &quot;cioc&quot;: &quot;&quot;
    },
    {
      &quot;name&quot;: &quot;Albania&quot;,
      &quot;topLevelDomain&quot;: [
        &quot;.al&quot;
      ],
      &quot;alpha2Code&quot;: &quot;AL&quot;,
      &quot;alpha3Code&quot;: &quot;ALB&quot;,
      &quot;callingCodes&quot;: [
        &quot;355&quot;
      ],
      &quot;capital&quot;: &quot;Tirana&quot;,
      &quot;altSpellings&quot;: [
        &quot;AL&quot;,
        &quot;Shqipëri&quot;,
        &quot;Shqipëria&quot;,
        &quot;Shqipnia&quot;
      ],
      &quot;region&quot;: &quot;Europe&quot;,
      &quot;subregion&quot;: &quot;Southern Europe&quot;,
      &quot;population&quot;: 2886026,
      &quot;latlng&quot;: [
        41,
        20
      ],
      &quot;demonym&quot;: &quot;Albanian&quot;,
      &quot;area&quot;: 28748,
      &quot;gini&quot;: 34.5,
      &quot;timezones&quot;: [
        &quot;UTC+01:00&quot;
      ],
      &quot;borders&quot;: [
        &quot;MNE&quot;,
        &quot;GRC&quot;,
        &quot;MKD&quot;,
        &quot;KOS&quot;
      ],
      &quot;nativeName&quot;: &quot;Shqipëria&quot;,
      &quot;numericCode&quot;: &quot;008&quot;,
      &quot;currencies&quot;: [
        {
          &quot;code&quot;: &quot;ALL&quot;,
          &quot;name&quot;: &quot;Albanian lek&quot;,
          &quot;symbol&quot;: &quot;L&quot;
        }
      ],
      &quot;languages&quot;: [
        {
          &quot;iso639_1&quot;: &quot;sq&quot;,
          &quot;iso639_2&quot;: &quot;sqi&quot;,
          &quot;name&quot;: &quot;Albanian&quot;,
          &quot;nativeName&quot;: &quot;Shqip&quot;
        }
      ],
      &quot;translations&quot;: {
        &quot;de&quot;: &quot;Albanien&quot;,
        &quot;es&quot;: &quot;Albania&quot;,
        &quot;fr&quot;: &quot;Albanie&quot;,
        &quot;ja&quot;: &quot;アルバニア&quot;,
        &quot;it&quot;: &quot;Albania&quot;,
        &quot;br&quot;: &quot;Albânia&quot;,
        &quot;pt&quot;: &quot;Albânia&quot;,
        &quot;nl&quot;: &quot;Albanië&quot;,
        &quot;hr&quot;: &quot;Albanija&quot;,
        &quot;fa&quot;: &quot;آلبانی&quot;
      },
      &quot;flag&quot;: &quot;https://restcountries.eu/data/alb.svg&quot;,
      &quot;regionalBlocs&quot;: [
        {
          &quot;acronym&quot;: &quot;CEFTA&quot;,
          &quot;name&quot;: &quot;Central European Free Trade Agreement&quot;,
          &quot;otherAcronyms&quot;: [],
          &quot;otherNames&quot;: []
        }
      ],
      &quot;cioc&quot;: &quot;ALB&quot;
    },
    ];
  
    const outputKeys = ['name', 'capital', 'region', 'languages', 'flag'];
  
  const output = ent.map(item =&gt;
    outputKeys.reduce((val, key) =&gt; ({ ...val, [key]: item[key] }), {})
  );
  console.log(output);
  
  
  </code></pre>
  <p>the Ouput is the array with the selected keys value is return but i need to flat the value of the object</p>
  <pre><code> const output = [
    {
      name: 'Afghanistan',
      capital: 'Kabul',
      region: 'Asia',
      languages: [
        [{
          iso639_1: 'ps',
          iso639_2: 'pus',
          name: 'Pashto',
          nativeName: 'پښتو'
        }],
        [{
          iso639_1: 'uz',
          iso639_2: 'uzb',
          name: 'Uzbek',
          nativeName: 'Oʻzbek'
        }],
        [{
          iso639_1: 'tk',
          iso639_2: 'tuk',
          name: 'Turkmen',
          nativeName: 'Türkmen'
        }]
      ],
      flag: 'https://restcountries.eu/data/afg.svg'
    },
    {
      name: 'Åland Islands',
      capital: 'Mariehamn',
      region: 'Europe',
      languages: [
        {
          iso639_1: 'sv',
          iso639_2: 'swe',
          name: 'Swedish',
          nativeName: 'svenska'
        }
      ],
      flag: 'https://restcountries.eu/data/ala.svg'
    },
    {
      name: 'Albania',
      capital: 'Tirana',
      region: 'Europe',
      languages: [
        {
          iso639_1: 'sq',
          iso639_2: 'sqi',
          name: 'Albanian',
          nativeName: 'Shqip'
        }
      ],
      flag: 'https://restcountries.eu/data/alb.svg'
    }
  ];
  
  </code></pre>
  <p>i need to flat the object value .[[{}],[{}],[{}]]</p>
  <p>experted the value to be language: [{},{},{}];</p>
  <p>i have tried to do like this:</p>
  <p>const outputKeys = ['name', 'capital', 'region', 'languages', 'flag'];</p>
  <p>const output = ent.map(item =&gt;
  outputKeys.reduce((val, key) =&gt; ({ ...val, [key]: item[key].flat(infinity) }), {})
  );
  console.log(output);</p>
  <p>look out the first object the language consist the nested arrays ! thanks in advance .</p>