Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Swap values with array destructuring

let a = 1, b = 2
[a, b] = [b, a]
console.log(a) // -> 2
console.log(b) // -> 1
Comment

How to Swap Two Array Elements by Destructuring

let myArray = [12, -2, 55, 68, 80];

[myArray[0], myArray[1]] = [myArray[1], myArray[0]];

console.log(myArray); // [-2,12,55,68,80]
Comment

PREVIOUS NEXT
Code Example
Javascript :: check when keyup an input from a specific form jquery 
Javascript :: javascript randomly shuffle array 
Javascript :: console log jquery 
Javascript :: js sentence to array 
Javascript :: make something visible js 
Javascript :: iterate over filelist javascript 
Javascript :: javascript iterate through object 
Javascript :: How to get unix timestamp from tomorrow nodejs 
Javascript :: js find object from value in array 
Javascript :: add class tr datatable 
Javascript :: js substring 
Javascript :: angular 10 get unique values from array of objects 
Javascript :: discord login js 
Javascript :: how to add sticky function in javascript 
Javascript :: open google chrome in puppeteer macos 
Javascript :: js go back 
Javascript :: disable server side rendering next.js 
Javascript :: js sort by name 
Javascript :: react useeffect not on first render 
Javascript :: how to clean react native project 
Javascript :: javascript json string 
Javascript :: nestjs cors origin 
Javascript :: Get parent directory name in Node.js 
Javascript :: query selector by href 
Javascript :: material ui datepicker remove error 
Javascript :: nodejs create buffer from string 
Javascript :: tailwind confirm 
Javascript :: javascript redirect example 
Javascript :: saving json file python 
Javascript :: regex detect negative numbers 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =