If you have 2 arrays classical and pop:
classical=["Beethoven","Mozart","Tchaikovsky"];
pop=["Beatles","Corrs","Fleetwood Mac","Status Quo"];
Why is that when you set all=classical+pop
it gives sets character in the array elements an individual character?
How do you correct this without retyping i.e. all=["Beethoven","Mozart","Tchaikovsky","Beatles"...]
Many thanks in advance.
Use the Array class concat() method to combine them on a new variable:
var all = classical.concat(pop);
+
is first converting both arrays to string, and then adding the strings. For this you need to use concat
method.
> classical=["Beethoven","Mozart","Tchaikovsky"];
["Beethoven", "Mozart", "Tchaikovsky"]
> pop=["Beatles","Corrs","Fleetwood Mac","Status Quo"];
["Beatles", "Corrs", "Fleetwood Mac", "Status Quo"]
> all = classical.concat(pop)
["Beethoven", "Mozart", "Tchaikovsky", "Beatles", "Corrs", "Fleetwood Mac", "Status Quo"]
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