Congratulations, you have completed the async and await lab! This is just a basic example, and there are many more advanced features and use cases that you can explore with async and await in JavaScript.JavaScript lab workbook for maps, sets, filters
Lab 1: Maps and Sets
In this lab, you will learn how to use Maps and Sets in JavaScript to organize and manipulate data.
Create a new JavaScript file and define an array of numbers:
javascriptCopy code
const numbers = [1, 2, 3, 4, 5];
Create a Map that maps each number to its square:
javascriptCopy code
const squareMap = newMap(); for (const number of numbers) { squareMap.set(number, number * number); } console.log(squareMap);
Create a Set that contains only the even numbers:
const evenSet = newSet(); for (const number of numbers) { if (number % 2 === 0) { evenSet.add(number); } } console.log(evenSet);
Use the forEach method to iterate over the values of the Map and Set:
squareMap.forEach((value, key) => { console.log(`${key} squared is ${value}`); }); evenSet.forEach((value) => { console.log(`${value} is even`); });
Use the size property to get the number of elements in the Map and Set:
console.log(`The squareMap has ${squareMap.size} entries.`); console.log(`The evenSet has ${evenSet.size} entries.`);
Lab 2: Filters and Reducers
In this lab, you will learn how to use filter and reduce to manipulate arrays in JavaScript.
Create a new JavaScript file and define an array of numbers:
const numbers = [1, 2, 3, 4, 5];
Use the filter method to create a new array that contains only the even numbers:
Congratulations, you have completed the async and await lab! This is just a basic example, and there are many more advanced features and use cases that you can explore with async and await in JavaScript.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (