Preheat the oven to 350°F (175°C). Grease a 9 × 5-inch loaf pan with cooking spray or a little oil. If desired, line the pan with parchment paper, leaving some overhang along the long sides to make removing the loaf easier.
Wash and dry the zucchini, then grate it using the medium holes of a box grater. Measure out 1 1/2 cups of grated zucchini. Gently squeeze it only if it is exceptionally watery. Removing too much moisture can make the finished bread dry, so the zucchini should remain slightly moist.
In a large mixing bowl, whisk together the granulated sugar, brown sugar, vegetable oil, eggs, and vanilla extract until smooth. Add the grated zucchini and stir until evenly distributed throughout the mixture.
In a separate bowl, whisk together the all-purpose flour, baking soda, baking powder, cinnamon, nutmeg, if using, and salt. This helps distribute the leavening agents and spices evenly throughout the bread.
Add the dry ingredients to the zucchini mixture. Fold gently with a spatula until the flour is just incorporated. Avoid overmixing, as this can make the loaf dense. If using walnuts or pecans, fold them into the batter at this stage.
Pour the batter into the prepared loaf pan and spread it evenly. Smooth the top with a spatula so the bread bakes uniformly.
Place the pan on the center rack and bake for 50 to 60 minutes. The top should be golden brown, and a toothpick inserted into the center should come out clean or with a few moist crumbs. If the top browns too quickly, loosely cover it with foil during the final 10 to 15 minutes.
Remove the loaf from the oven and let it cool in the pan for 10 to 15 minutes. Transfer it to a wire rack and allow it to cool further before slicing. Cooling helps the crumb set and makes it easier to cut neat slices.