swap elements in array javascript
var b = list[y];
list[y] = list[x];
list[x] = b;const heavy = ["Rammstein", "Motorhead", "Imsomnium", "Be´lakor"];
let aux = "";
const intercambiar = (arr, i1, i2) => {
//Guardo en un provisional el valor del primer indice
aux = arr[i1];
//Inserte el valor del segundo índice en el lugar del primer índice
arr[i1] = arr[i2];
// Al hacer esto pierdo el valor original pero lo tengo guardado en aux por
//lo que solo necesito igualar el segundo índice a aux para completar
//el ejercicio.
arr[i2] = aux;
return arr;
};
let resulIntercambiar = intercambiar(heavy, 1, 2);
console.log(resulIntercambiar);
Also in JavaScript:
- how to test useeffect with enzyme
- how to make sticky footer with react router
- math.max in javascript
- --resolveJsonModule
- find base url in javascript
- react state array push
- c# parse json
- javascript create object from key value pairs
- settimeout inside loop
- value is array
- encode url javascript
- difference between var let and const in javascript with example
- toLocalString
- Material-ui add circle icon
- firebase app named default already exists react native
- regex contains string in end
- how to remove menu bar in electron app without removing frame
- javascript jqgrid events afterShowForm
- ignore node modules
- javascript array filter
- how to send json data in fetch request body
- postgresql nodejs
- how to use props in functional component in react
- jquery not working in jqurey insertet part