Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to swap two elements in an array javascript

// Before ES6
const temp = a[x]; // NOT RECOMMENDED UNLESS COMPLETELY UNAVOIDABLE
a[x] = a[y];
a[y] = temp;
 
PREVIOUS NEXT
Tagged: #swap #elements #array #javascript
ADD COMMENT
Topic
Name
2+6 =