NEW YORK (Reuters) - Walmart Inc WMT.N posted its best quarterly U.S. sales growth in a decade and upped full-year sales and profit outlooks on Thursday, sending shares surging as a jump in online and grocery purchases showed it can hold its own against Amazon.com Inc AMZN.O.

The world’s largest retailer is known for its sprawling stores, a factor that could have worked against it as shoppers migrate online. But Walmart is also the top U.S. grocer, providing a lure for customers to visit stores, where they may also make other impulse buys.

Walmart has also overhauled its website and worked to use physical locations as distribution points for online orders of groceries and other goods, helping retain buyers who increasingly expect quick, cheap shipping.

Consumers spent more on categories like grocery, apparel and seasonal merchandise in the second quarter, helping sales rebound after a slow start in April. Walmart has recorded four straight years of U.S. growth, unmatched by any other retailer.

“We saw strong performance in fresh food,” U.S. Chief Executive Greg Foran said on an earnings conference call, praising sales in produce, meat and bakery. Grocery sales rose the most in nine years.

Walmart benefited from improved weather in May, the first month of the quarter, seeing the biggest quarterly gain in customer traffic in more than six years, Chief Financial Officer Brett Biggs told Reuters.

Rising wages, lower unemployment and tax cuts that have put more money in U.S. consumers’ pockets this year also helped.

“(This) is a reflection of Walmart’s various in-store and online initiatives, and likely an indication of solid market share gains, and an overall healthy consumer backdrop,” Credit Suisse analysts said in a note.

Walmart’s U.S. e-commerce growth ticked higher than previous quarters, driven by a website redesign and continued expansion of online grocery offerings.

A Walmart logo is displayed above the floor of the New York Stock Exchange shortly after the opening bell in New York, U.S., August 16, 2018. REUTERS/Lucas Jackson

Sales growth has come at some cost, however, with the company citing continued margin pressures driven by cutting prices, higher freight costs due to a shortage of truck drivers and e-commerce investments.

Walmart’s shares were up 10 percent at $99.08. The company’s stock had fallen around 9 percent since the start of the year.

STRONG ONLINE SALES

Walmart raised its sales and earnings outlook for the full year, excluding any impact from its acquisition of Indian e-commerce company Flipkart, which it is still in the process of closing.

E-commerce sales grew 40 percent in the quarter, up from 33 percent growth in the previous period, and the retailer said U.S. online sales are on track to rise 40 percent for the full year.

Walmart now offers curbside pickup of online grocery orders in 1,800 U.S. stores, and the service is bringing in new customers, Biggs said.

A sharp online sales slowdown during the crucial holiday months had spooked investors, who worried the retailer would not be able to keep pace with Amazon.

Cowen & Co estimates that 86 percent of Walmart shoppers also shop on Amazon.

Still, e-commerce losses could be higher this year than last year as it continues to invest in the business, Walmart’s e-commerce chief Marc Lore said on the call.

Gross margins fell for the fifth consecutive quarter and were down 17 basis points, the company said.

OVERSEAS SALES JUMP

International sales were up 3.1 percent at $29.2 billion on a constant currency basis, helped by strong comparable sales in Mexico, Britain, Canada and China.

Separately, Asda, Walmart's British supermarket arm, reported a 2.6 percent rise in quarterly sales on Thursday, ahead of an expected takeover by bigger rival Sainsbury's SBRY.L.

Walmart sold a majority stake in ASDA to Sainbury’s in April.

In June, Walmart sold an 80 percent stake in its Brazilian operations to private equity firm Advent International. It paid $16 billion for a majority stake in Flipkart.

The retailer also reached agreements to sell its banking operations in Walmart Canada and Walmart Chile.

Sales at U.S. stores open at least a year rose 4.5 percent, excluding fuel price fluctuations, higher than analyst forecasts of 2.38 percent, according to Thomson Reuters I/B/E/S.

Excluding one-time items such as a loss related to the sale of a majority stake in Walmart Brazil, Walmart earned $1.29 per share, ahead of analysts’ expectations of $1.22 per share.

Total revenue increased 3.8 percent to $128 billion, beating estimates of $125.97 billion.

For the full year, Walmart expects to earn between $4.90 and $5.05 per share, up from a range of $4.75 to $5 a share. The retailer said same-store sales in the United States should rise about 3 percent in fiscal 2019, up from a prior target of at least 2 percent.