By Sarah Nassauer

Walmart Inc. 's quarterly sales surged as the retail behemoth continued to use its scale, e-commerce supply chain and grocery business to attract shoppers buying food and household goods during the coronavirus pandemic.

The company's e-commerce business nearly doubled, jumping 97% from a year ago, boosted by people ordering groceries online to pick up in store parking lots. Walmart expanded the availability of delivery and pickup time slots this year in response to the health crisis.

Comparable U.S. sales, those at stores or digital channels operating for at least 12 months, rose 9.3% in the quarter ended July 31. It marks the second consecutive quarter of strong growth and evidence that the world's largest retailer is grabbing market share as many retailers close stores or declare bankruptcy amid coronavirus struggles.

In the April quarter Walmart's comparable U.S. sales grew 10% and Wall Street was expecting growth of 5.9% for the July quarter, according to estimates compiled by FactSet.

U.S. traffic fell 14% in the July quarter, while the average amount spent per transaction jumped 27%. In the U.S. "customers continued to consolidate store shopping trips," spending more per trip, the company said in a release, "and shifted more purchases to e-commerce."

Walmart said sales were boosted by government stimulus spending, which lifted demand for general merchandise such as electronics, patio furniture, sporting goods and even apparel, a category with weak sales at the start of the pandemic. As the government funds tapered off, sales started to return to more normal levels in the month of July, the company said.

Net income was $6.48 billion, compared with $3.61 billion a year ago. The latest period included a large investment gain. Excluding gains and one-time charges, Walmart said it had adjusted earnings of $1.56 cents a share. On that basis, analysts were expecting $1.25 a share, according to FactSet.

Also on Tuesday, Home Depot Inc. said comparable sales rose a record 23.4% in the quarter ended Aug. 2, as more people spend more time at home, sprucing up the house with remodeling and decorating projects. Meanwhile, Kohl's Corp. reported total revenue fell 23% as it worked to reopen its department stores.

Many already weakened retailers have buckled under the pressure of the pandemic. Several department stores and specialty retailers have filed for bankruptcy protection with plans to close many stores, including Lord & Taylor, J.C. Penney Co. and Stage Stores Inc. Last week, off-price chain Stein Mart Inc. filed for chapter 11 with plans to close most of its roughly 280 stores.

Along with Amazon.com Inc., Walmart, Home Depot and other large retailers have been coronavirus winners. They have significant online businesses or have largely stayed open, have been deemed essential retailers by local governments and sell goods that align with quickly shifting buying habits. Shoppers are spending more on cooking at home, fixing up homes and family entertainment, while spending less on restaurants, travel and office-ready fashion.

Target Corp. and home-improvement retailer Lowe's Cos. report quarterly results Wednesday.

But as retailers approach the busy holiday season, the economic outlook is unclear. Supplemental unemployment benefits ended last month for tens of millions of Americans and are set to restart at reduced levels.

Walmart's business model aligns well with many coronavirus-related forces. Already the country's biggest seller of groceries, Walmart has invested heavily to offer curbside pickup or home delivery from hundreds more stores. Those services had all-time high sales volumes in the quarter, the company said. The retailer, which touts low prices, typically grows sales when the economy falters, according to analysts. And Walmart sells everything from lettuce to underwear and vacuums, making it a convenient one-stop shop for shoppers limiting their time in public spaces for health reasons.

Early in the pandemic Walmart struggled to keep shelves stocked as shoppers panic-bought toilet paper, cleaning supplies and food. Over a hundred thousand workers were on coronavirus-related leave in April. The retailer rushed to quickly hire enough staff to keep up. Inventory strain has stabilized somewhat, but Walmart is still facing above normal out-of-stock product rates, it said Tuesday. U.S. inventory levels were 4.6% below year-ago levels.

Write to Sarah Nassauer at sarah.nassauer@wsj.com