How to swap two values of an array in Node.js

1 Answer

0 votes
let arr = [9, 333, 7, 0, 2, 1, 8, 6];
 
[arr[1], arr[4]] = [arr[4], arr[1]];
 
console.log(arr);
   
  
   
    
/*
run:
     
[ 9, 2, 7, 0, 333, 1, 8, 6]
        
*/

 



answered Apr 20, 2023 by avibootz

Related questions

1 answer 141 views
2 answers 132 views
1 answer 184 views
1 answer 117 views
117 views asked Nov 6, 2022 by avibootz
2 answers 170 views
1 answer 215 views
...