By Rodrigo Campos

NEW YORK (Reuters) - The S&P 500 edged higher on Wednesday to cap a four-day losing streak, buoyed by gains in Apple shares and after the Federal Reserve kept U.S. interest rates unchanged, as expected.

Apple <AAPL.O> shares rose 6.1 percent to $128.75, its highest close in a year and a half. This made it the biggest positive influence on the three major indexes, which would have all ended in the red for the day without Apple's boost.

In its first meeting since President Donald Trump took office, the Fed's policy-setting committee said job gains remained solid and was upbeat on inflation, signaling conviction that the economy was on a good footing.

The lack of detail on when the next rate hike could come weighed on financial shares, which had been positive through most of the session. The S&P 500 financial sector <.SPSY> edged up 0.04 percent.

"Confidence in the economy was reflected in the more emphatic (Fed) statement with regard to inflation," said Atul Lele, chief investment officer at Deltec International Group in Nassau, Bahamas.

He said the Fed suggested a wait-and-see approach when it came to the fiscal stimulus expected to be triggered by the Trump administration.

Data earlier in the day showed U.S. factory activity accelerated to a more than two-year high in January and private employers boosted hiring last month.

However, stocks struggled to gain momentum and the S&P 500 avoided its fifth session of consecutive declines by the slightest margin.

The Dow Jones Industrial Average <.DJI> rose 26.85 points, or 0.14 percent, to end at 19,890.94, the S&P 500 <.SPX> gained 0.68 point, or 0.03 percent, to 2,279.55 and the Nasdaq Composite <.IXIC> added 27.87 points, or 0.5 percent, to 5,642.65.

Dow component Exxon <XOM.N> slipped 1.1 percent after a string of price target cuts from brokerages. The oil major had reported results on Tuesday.

Johnson Controls <JCI.N> fell 3.4 percent to $42.50 after its quarterly organic sales growth fell short of its estimate.

On the upside, Facebook <FB.O> shares added almost 2 percent in extended trading following higher-than-expected quarterly profit and revenue.

During the regular session, Advanced Micro Devices <AMD.O> rallied 16.3 percent to $12.06 in nearly four times its usual daily volume a day after reporting results.

Declining issues outnumbered advancing ones on the NYSE by a 1.09-to-1 ratio; on Nasdaq, a 1.01-to-1 ratio favored advancers.

The S&P 500 posted 30 new 52-week highs and two new lows; the Nasdaq Composite recorded 135 new highs and 27 new lows.

About 7.59 billion shares changed hands in U.S. exchanges, above the 6.8 billion daily average over the last 20 sessions.

(Reporting by Rodrigo Campos; Editing by Chizu Nomiyama and James Dalgleish)