JavaScript How-To Guides
Practical, runnable how-to guides for common JavaScript tasks.
All JavaScript how-to guides pages
How to Merge Objects in JavaScript
Merge two or more objects with the spread operator or Object.assign(), understand how key conflicts resolve, and know why both do a shallow merge.
How to Remove Duplicates from an Array in JavaScript
Get the unique values from an array — with a one-line Set for primitives, and a Map when you need to de-duplicate objects by a key.
How to Reverse a String in JavaScript
Reverse a string with the split–reverse–join one-liner, understand why each step is needed, and handle emoji and accented characters correctly.
How to Sort an Array in JavaScript
Sort numbers, strings, and objects correctly with Array.prototype.sort() — and avoid the default-sort trap that turns [10, 1, 2] into [1, 10, 2].
Practical JavaScript how-to guides: each one takes a single task and shows the clearest correct way to do it, the common mistakes to avoid, and code you can run and adapt.
Pick a task below, or run any solution in the JavaScript online compiler.