I was making some tests with the JS's split() string method in Firefox's console. While testing I did the following:
test = 'first second third'.split(' ')
-> Array [ "first", "second", "third" ]
test
-> Array [ "first", "second", "third" ]
name = 'first second third'.split(' ')
-> Array [ "first", "second", "third" ]
name
-> "first,second,third"
I noticed that everytime I called the split() method it returned an Array but if I saved it in a variable called name then it was saved as a string rather than an Array.
Why does this happens?
This issue will only come from window.name, due to the way it's setter and/or getter is defined. If you use the variable name inside a function, you won't face this issue.
In case you're curious to see how window.name changes the output from the array to a string, here is a quick example I made: JSFiddle.
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