how to swap two elements in an array javascript
// Since ES6
[a[0], a[1]] = [a[1], a[0]]// Before ES6
const temp = a[x]; // NOT RECOMMENDED UNLESS COMPLETELY UNAVOIDABLE
a[x] = a[y];
a[y] = temp;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:
- IFFI in js
- node_modules/metro/src/lib/attachWebsocketServer.js
- Mobx-react console warning related observer
- javascript backslash
- js is empty object
- deploy react to aws
- jsx full form
- js is object empty
- make shorter if statements with objects
- javascript array to csv string
- jquery droppable allow what can be dropped
- js array map skip element
- all math methos js
- how to paste in input field react native
- negative indexing in arrays javascript
- Please update your node with version 8.11.3 or greater (but not version 10)
- "rbac" react redux navigation bar
- angular @Output()
- javascript clear localstorage
- jquery bind click
- uncheck checkbox when another is checked javascript
- javascript string first letter lowercase
- html shortcuts in jsx
- How to call the ajax when form is valid