Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to Swap Two Array Elements by Destructuring

let myArray = [12, -2, 55, 68, 80];

[myArray[0], myArray[1]] = [myArray[1], myArray[0]];

console.log(myArray); // [-2,12,55,68,80]
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #Swap #Two #Array #Elements #Destructuring
ADD COMMENT
Topic
Name
9+3 =