Created
January 9, 2024 14:40
-
-
Save felixjb/c11b4851b2a92b93ef0e994b09539c8b to your computer and use it in GitHub Desktop.
A collection of helpful tricks on JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a Map from an Array | |
const array = [ | |
{ key: "name", value: "Tom" }, | |
{ key: "country", value: "Chile" }, | |
]; | |
// Return an array of tuples (array with two values, the key and the value) | |
const map = new Map(array.map((item) => [item.key, object.value])); | |
// ️👇️ {'name' => 'Tom', 'country' => 'Chile'} | |
console.log(map); | |
// Swap two variables in one line (XOR) | |
let [a, b] = [0, 1]; | |
[a, b] = [b, a]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment