Objects and Key-Value Utilities
Key takeaway: Practice JavaScript with 102+ runnable code examples — variables, arrays, strings, objects, math, dates, and DOM — all with expected output to verify instantly.
JavaScript is a programming language that makes web pages interactive. These examples are for front-end developers, bootcamp students, self-taught coders, and anyone preparing for JS interviews.
Last updated: October 2026 · 102 examples
Quick Start
- Pick an example from the sidebar or mobile menu
- Study the code and expected output
- Run it in our online JS compiler or browser console
- Modify the code to experiment
Who is this for: Front-end developers, bootcamp students, interview candidates, and self-taught coders building JavaScript skills. Use this when: you need quick reference code, want to practice for interviews, or learn JS concepts hands-on.
Related:JS Projects · JS Tutorial · JS Compiler · TypeScript Examples · Python Examples · MDN JavaScript Docs
JavaScript Program to Check if a Key Exists in an Object
Use in operator.
const o={a:1}; console.log("a" in o);JavaScript Program to Create Objects in Different Ways
Object literal, constructor, class.
const o1={x:1}; function Person(n){this.name=n;} const o2=new Person("Ann"); class Car{constructor(m){this.model=m;}} const o3=new Car("Civic"); console.log(o1,o2,o3);JavaScript Program to Remove a Property from an Object
Delete a property.
const o={a:1,b:2}; delete o.b; console.log(o);JavaScript Program to Clone a JS Object
Clone using structuredClone.
const o={a:1,b:{c:2}}; const c=structuredClone(o); console.log(c);JavaScript Program to Loop Through an Object
Loop entries.
const o={a:1,b:2}; for(const [k,v] of Object.entries(o)){ console.log(k,v); }JavaScript Program to Merge Property of Two Objects
Merge using spread.
const a={x:1}, b={y:2}; const c={...a,...b}; console.log(c);JavaScript Program to Count the Number of Keys/Properties in an Object
Use Object.keys length.
const o={a:1,b:2,c:3}; console.log(Object.keys(o).length);JavaScript Program to Add Key/Value Pair to an Object
Assign a new key.
const o={}; o.name="Alice"; console.log(o);JavaScript Program to Sort Array of Objects by Property Values
Sort by property.
const a=[{n:2},{n:1}]; a.sort((x,y)=>x.n-y.n); console.log(a);Keep Practicing
Use the online compiler to run examples and test variations. Reinforce learning by building small scripts for each topic.
FAQ
Learn JavaScript by Practicing Examples
Hands-on practice is the fastest way to understand JavaScript. Each example above focuses on a single concept—from strings, arrays, and objects to math utilities, dates, loops, and functions. Try editing variables, adding conditions, or refactoring logic, then observe the output changes instantly.
Use our tools to deepen your learning: JavaScript Compiler to run snippets, and the JavaScript Tutorial for guided theory and practice.
Beginner-Friendly
Start with variables, operators, and control flow. Build confidence with simple, readable programs.
Practical Patterns
Practice common tasks like formatting strings, manipulating arrays, and working with dates.
Grow Skills
Advance to objects, classes, and asynchronous patterns such as promises and async/await.