This week, two of the three major stock indexes reached all-time highs, driven by a surge in companies closely associated with the artificial intelligence.

The S&P 500 rose by 2.10% to $5,353, surpassing its previous all-time closing high set on May 23. Meanwhile, the tech-heavy Nasdaq Composite jumped nearly 2.59% to $17,186, breaking its earlier record set on May 28.

S&P 500 / Nasdaq Composite Chart by TradingView

These record-breaking peaks coincided with two of the three most valuable stocks achieving market capitalizations exceeding $3 trillion. Nvidia reached this milestone for the first time, while Apple surpassed it for the first time since January.

Nvidia / Apple Market Cap Chart by TradingView

Nvidia stock has been rapidly climbing the ranks of the world's largest companies. On February 19, the chipmaker overtook e-commerce and cloud computing giant Amazon to become the third-largest U.S. company. Now, just three months later, Nvidia has ascended to the second spot, displacing iPhone maker Apple, after adding $1.2 trillion in new market value.

This week, shares of Nvidia, the dominant player in the AI chip market, surged by 9% to an all-time high.

Nvidia Stock Chart by TradingView

Led by CEO Jensen Huang, Nvidia is the third U.S. company to ever reach a $3 trillion market cap, following Apple and Microsoft. To claim the top spot from Microsoft, Nvidia would need to gain approximately $150 billion in market value.

Microsoft surpassed Apple earlier this year to become the most valuable U.S. company. Apple, which had long held the title and was the first company to reach market caps of $1 trillion and then $2 trillion, has seen its growth stall this year due to issues such as demand fluctuations in China, manufacturing challenges, and the reception of its mixed-reality headset, Vision Pro.