Who says traditional retailers can’t compete with Amazon.com?

Walmart Inc (wmt, +9.61%) reported on Thursdaythat its U.S. comparable sales rose 4.5% in the second quarter, their fastest clip in a decade, sending shares up 9% and showing that the mass merchant is holding its own against its primarily digital rival.

The world’s largest retailer clearly got a boost from the best consumer spending environment in memory. But it has done a lot to help itself in recent years. Walmart’s efforts have included moves like giving workers raises and more training, remodeling its grocery areas, making grocery pickup of online orders available at 1,800 stores so far, updating its app, better integrating its stores and e-commerce, and vastly expanding its e-commerce offering.

On top of the sales gains, most encouraging for Walmart is that store visits in the U.S. were up 2%, as was how much people spend per trip. Walmart U.S. CEO Greg Foran told reporters on a briefing that new shoppers were coming in and existing shoppers were typically adding an item to their shopping cart nowadays. Walmart’s momentum extending to its online business where U.S. sales rose 40%, a crucial return to form.

On the strength of the second quarter, Walmart said it now expects its…