practicecommonarraysmethods // Arrays to store orders const drinks = ["Latte", "Tea", "Espresso"]; const pastries = ["Croissant", "Muffin", "Bagel"]; console.log("Number of drinks:", drinks.length); console.log("Number of pastries:", pastries.length); // Example combinations: console.log("First drink:", drinks[0]); // Latte console.log("Last pastry:", pastries[pastries.length - 1]); // Bagel
// Additional combinations: console.log("Second drink:", drinks[1]); // Tea console.log("First pastry:", pastries[0]); // Croissant console.log("Third drink:", drinks[2]); // Espresso // Assign indices to variables const drinkIndex = 1; // for example, second drink const pastryIndex = 2; // third pastry
console.log("Dynamically accessed drink:", drinks[drinkIndex]); console.log("Dynamically accessed pastry:", pastries[pastryIndex]); // Adding new orders drinks.push("Cappuccino"); pastries.push("Danish");
console.log("Updated number of drinks:", drinks.length); console.log("Updated number of pastries:", pastries.length); // Add "flat white" to the drinks array drinks.push("Flat White");
// Log the updated number of drinks console.log("Updated number of drinks:", drinks.length);