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 128 views
2 answers 123 views
1 answer 155 views
1 answer 109 views
109 views asked Nov 6, 2022 by avibootz
2 answers 154 views
1 answer 193 views
...