I am a bit confused by the behavior of Array.map
function here:
var arr = ['one', 'two', 'three'];
var result = '';
result += arr.map(function(elm) {
return elm;
});
// 'one,two,three'
How does it automatically join the returned results with a ,
?
Note: This only happens if I concatenate the returned result in a string.
Array.map
did nothing to your array.
You basically did this
'' + ['one', 'two', 'three']
Which calls the toString()
method of an array, whose default behaviour is to join(',')
the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With