Skip to content Skip to sidebar Skip to footer

Javascript Concat Not Working As Expected, Care To Elaborate?

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 I g

Solution 1:

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]);

Post a Comment for "Javascript Concat Not Working As Expected, Care To Elaborate?"