When I write the code below everything is reversed on output as expected.
var sequence = "kick snare hat openHat";
var sequenceBackwards = sequence.split('').reverse().join('');
document.write(sequenceBackwards);
However when I have an Array, then convert it to a string then do the same proceedure it doesn’t work.
var sequence = ["kick","snare", "hat","openHat"];
sequence.toString();
var sequenceBackwards = sequence.split('').reverse().join('');
document.write(sequenceBackwards);
I would like to know exactly why this doesn’t work, and a working alternate example.
When I do a “typeof” for sequenceBackwards it doesn’t return string.It returns object which tells me it’s still an array after the supposed “conversion”. I’m a bit confused on this.
I am not doing this for a project I’m curious and have been picking at it for an hour.
This line does not change
sequencevariable, it justreturnsstring:sequence.toString();["kick", "snare", "hat", "openHat"].toString()provides"kick,snare,hat,openHat". So it is not what are you looking for.Use