JavaScript Objects & Manipulation — Beginner Friendly Guide

Himmat Kumar Mar 30, 2025, 11:37 AM
Blog Thumbnail

🧠 JavaScript Objects and their Manipulations

📦 Object Creation

An example of a user-related simple object is shown below.

const user = { name: "Alice", age: 25, email: "alice@example.com" };

🔍 Accessing Values of an Object’s Property

You can access values by the property name through the dot or the brackets notation.

console.log(user.name); // Alice

console.log(user["email"]); // alice@example.com

📝 Modifying An Object's Field

To make a change to the object, assign a different value to that key.

user.age = 26;

user["email"] = "alice.new@example.com";

➕ Property Addition

It is also possible to add properties dynamically.

user.country = "India";

❌ Object Property Removal

To remove a given property, employ the delete operator.

delete user.age;

🔁 Object Key Iteration

A for…in loop will iterate all keys.

for (let key in user) {

console.log(key + ": " + user[key]);

}

✅ TL;DR: Object Cheatsheet

  • To create: const obj = { key : value }
  • To access: obj.key or obj[“key”]
  • To update: obj.key = new Value
  • To add: obj.newKey = value
  • To delete: delete obj.key
  • To loop: for…in for iterating in the keys or values.
💡 Pro Tip: Managing data that is structured like users, their settings, or any other containing multi-values, would be easier with object-oriented programming.

Comments

Please login to leave a comment.

No comments yet.

Related Posts

javascript-data-types-explained
Himmat Kumar Mar 25, 2025, 12:17 PM

JavaScript Data Types Explained with Examples

introduction-to-javascript
Himmat Kumar Oct 27, 2023, 11:36 AM

Introduction JavaScript

javascript-functions-and-scope-guide
Himmat Kumar Mar 30, 2025, 5:26 AM

JavaScript Functions & Scope

javascript-date-and-time-guide
Himmat Kumar Mar 30, 2025, 6:46 AM

Date and Time in JavaScript — Easy Guide

javascript-variables-var-let-const-explained
Himmat Kumar Mar 25, 2025, 12:03 PM

JavaScript Variables: var vs let vs const

javascript-loops-for-while-do-while
Himmat Kumar Mar 29, 2025, 5:43 AM

JavaScript Loops — for, while, do...while

laravel-configuration
228 viewsLaravel
Himmat Kumar Dec 4, 2024, 11:58 AM

Laravel Configuration