Created
May 23, 2023 01:49
-
-
Save kironroy/6d519444ba3d59cc87fc759d0f611876 to your computer and use it in GitHub Desktop.
map iteration js
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
console.log('----------new map--------------'); | |
const question = new Map([ | |
['question', 'What is the best programming language in the world'], | |
[1, 'C'], | |
[2, 'Java'], | |
[3, 'JavaScript'], | |
['correct', 3], | |
[true, 'Correct 😊'], | |
[false, 'try again'], | |
]); | |
console.log(question); | |
console.log(question.get('question')); | |
for (const [key, value] of question) { | |
if (typeof key === 'number') { | |
console.log(`Answer ${key}: ${value}`); | |
} | |
} | |
// const answer = Number(prompt('Your answer')); | |
// console.log(answer); | |
// console.log(question.get(question.get('correct') === answer)); | |
// convert map to array | |
console.log([...question]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment