If Israel has nukes, it has them for the same reasons other countries have them, as a last line of defense in the event the country is in danger of being overrun and as a possible deterrent to attacks. Arguably, Israel has a greater need for nukies than any of the other nuclear powers, since if the others lost a war they would be unlikely to be overrun by the enemy, but the 7,500,000 Israelis are surrounded by 500,000,000 Arabs and Iranians who would certainly erase the Jewish nation from the map if they could.
Despite the fact that Iran has been carrying out terrorist attacks against Israeli civilians through its Arab proxies, Hezbollah, Hamas and Islamic Jihad, for decades, Israel never attacked or threatened to attack Iran because of this. Israel's threats have been exclusively against Iran's nuclear weapons programs because of Iran's frequent threats to destroy the Jewish nation. Without nukes, Iran could not carry out its ambition to destroy the Jewish state, but with nukes and effective missiles, which it already has, it could literally wipe Israel off the map and there is reason to think it would despite that threat of an Israeli retaliatory nuclear strike against Iran.
RAFSANJANI SAYS MUSLIMS SHOULD USE NUCLEAR WEAPON AGAINST ISRAL
Before the Islamists took over in 1979, Israel and Iran had friendly relations, and even after the 1979 Islamist takeover, when Iran was in danger of being overrun by Iraq, Israel sold Iran, with US permission, thousands of Tow and Hawk missiles to stop Saddam's tanks and planes at a time when no other country in the world would sell Iran advanced weapons.
But Iran is not a rational actor. Its enmity towards Israel derives entirely from the fact that Israel is a Jewish nation. Given the horrific repression of dissent, or even of independent thinking, that has been going on in Iran since the revolution and the regularity with which Muslim nations in the region carry out atrocities against their own citizens or attack and ravage neighboring countries, it is clear that if Israel were a Muslim country the criticisms Iran and other Islamic extremists level against it would not even raise an Ayatollah's eyebrow.