It should be:
[array[j], array[j + 1]] = [array[j + 1], array[j]];
instead of:
[array[j], array[j + 1] = array[j + 1], array[j]];
Pay close attention to where the square brackets begin and end.
Your current code:
- assigns one array index to itself
- creates an array with 3 elements
- and throws it away immediately
What you actually want is a destructuring assignment. (thanks to @Reyno for the link!)
solved Correct bubble sort in JS doesn’t do anything