So I had en experiment I want to share here, because I didn't understand the reason why it happened and I can't find out a proper reason yet on SO or Google.
With the following code :
const cities = [
['p','a','r','i','s'],
['n','e','w',' ','y','o','r','k'],
['s','a','n',' ','f','r','a','n','c','i','s','c','o']
]
const citiesCopy = [...cities];
const citiesWithUppercase =
citiesCopy
.map(city => {
['a', 's'].forEach((letter, i) => {
city.includes(letter) && (city[city.indexOf(letter)] = letter.toUpperCase());
})
return city
})
console.log("cities", cities);
I expect the result of the console.log
to be the original cities
with lower case letters for a
and s
, as I am working only on a copy of cities
, but actually they are upper case. Copy paste in your own console to see the result.
Can somebody explain why ?