JavaScript concat not working as expected, care to elaborate?

前端 未结 1 874
挽巷
挽巷 2021-01-25 08:33

So, I have this object containing country names as keys and the values are arrays with some cities. I want to get all the cities in one array, without the countries. Here\'s how

相关标签:
1条回答
  • 2021-01-25 08:56

    As per documentation of Array.prototype.concat:

    Returns a new array comprised of this array joined with other array(s) and/or value(s).

    Which means it does not modify the object it is applied to.

    Change to:

    allCities = allCities.concat(cities[c]);
    
    0 讨论(0)
提交回复
热议问题