Home / E-commerce and Business / Wishlist and Compare

Wishlist and Compare in JavaScript, Free with Live Demo

Free wishlist and product compare in plain JavaScript. Save favourites with a heart, keep them after reload, share the list as a link, and compare up to three products with differences highlighted.

Open live demoDownload HTML fileView code on GitHub
Wishlist and Compare JavaScript project: heart products to a saved wishlist and compare up to three side by side

Runs on: localStorage and URL parameters. Works in all modern browsers.

What is the Wishlist and Compare?

A product grid where every item has a heart for the wishlist and a Compare tick box. Saved items stay after a reload and can be shared as a link.

Pick two or three products and open a comparison table that highlights rows where they differ and shows the best price, rating, delivery time and warranty in green.

Good for

  • Furniture and electronics shops
  • Comparing plans or courses
  • Property and car listings
  • Gift lists

What this project does

How it works

  1. A set of saved idsThe wishlist is a Set of product ids saved to localStorage, so hearts stay filled after a reload or a new visit.
  2. Share as a linkThe share link adds ?w=0,2,5 to the page address. Opening it merges those products into the other person's wishlist.
  3. Compare what differsFor up to three products, each row checks if the values differ and highlights the row, and marks the best value, like the lowest price.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

const wish = new Set(JSON.parse(localStorage.getItem("wish") || "[]"));
heart.onclick = () => {
  wish.has(id) ? wish.delete(id) : wish.add(id);
  localStorage.setItem("wish", JSON.stringify([...wish]));
};
shareInput.value = location.origin + location.pathname + "?w=" + [...wish].join(",");

const values = picked.map((p) => p.price);
const differs = new Set(values).size > 1;
const best = Math.min(...values);

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

Should the wishlist be saved on the server?

For signed in customers, yes, so it follows them across devices. For guests, localStorage is simple and works well.

Why only three to compare?

More than three columns gets hard to read, especially on phones.

Is the share link private?

It only lists product numbers, nothing personal. Anyone with the link sees those products.

More E-commerce and Business projects