The following code:
var words = ['javascript', 'hmtl', 'css', 'python'];
words[0] = words[3];
words[3] = words[0];
alert(words);
...gives the below:
python,hmtl,css,python
python,hmtl,css,python, instead of python,hmtl,css,javascript, if there is no temporary variable?Would you Guys be able to help with the above, please?
if you want to swap without a temp variable use the ES6 array destruction syntax; simply do the following [words[0],words[3]]=[words[3],words[0]]