Code snippets
Code snippets
Copy-ready answers to everyday coding questions, each with a short explanation. Laravel, PHP, JavaScript, SQL, Bash and more.
2 snippets tagged #unique · Show all
SQL
October 20, 2026
MySQL INSERT ON DUPLICATE KEY UPDATE upsert
Inserts a row, or updates it if a unique key already exists. The table needs a UNIQUE or PRIMARY KEY on the column you match.
INSERT INTO page_views (page, views)
VALUES ('/home', 1)
ON DUPLICATE KEY UPDATE views = views + 1;
JavaScript
October 14, 2026
JavaScript remove duplicates from an array
A Set keeps only unique values, so spreading it back into an array removes duplicates. For objects, dedupe by a key with a Map.
const nums = [1, 2, 2, 3, 3, 3];
const unique = [...new Set(nums)];
console.log(unique); // [1, 2, 3]