VOOZH about

URL: https://www.digitalocean.com/community/tutorials/understanding-objects-in-javascript

⇱ Understanding Objects in JavaScript | DigitalOcean


Understanding Objects in JavaScript

Updated on August 25, 2021
πŸ‘ Understanding Objects in JavaScript

Introduction

An object in JavaScript is a data type that is composed of a collection of names or keys and values, represented in name:value pairs. The name:value pairs can consist of properties that may contain any data type β€” including strings, numbers, and Booleans β€” as well as methods, which are functions contained within an object.

Objects in JavaScript are standalone entities that can be likened to objects in real life. For example, a book might be an object which you would describe by the title, author, number of pages, and genre. Similarly, a car might be an object that you would describe by the color, make, model, and horsepower. JavaScript arrays are also a type of object.

Objects are an integral and foundational aspect of most JavaScript programs. For example, a user account object may contain such data as usernames, passwords, and e-mail addresses. Another common use case is a web shopping platform’s shopping cart that could consist of an array of many objects containing all the pertinent information for each item, such as name, price, and weight for shipping information. A to-do list is another common application that might consist of objects.

In this tutorial, we will review how to create an object, what object properties and methods are, and how to access, add, delete, modify, and loop through object properties.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

Tutorial Series: How To Code in JavaScript

JavaScript is a high-level, object-based, dynamic scripting language popular as a tool for making webpages interactive.

About the author(s)

Software engineer and open source creator

Community and Developer Education expert. Former Senior Manager, Community at DigitalOcean. Focused on topics including Ubuntu 22.04, Ubuntu 20.04, Python, Django, and more.

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

This is a nice primer, thanks!

This explains a lot ,but I don’t really understand the β€œ$” in the code

gimli.fight = function() { return Gimli attacks with an ${this.weapon}.; }

I would appreciate if it could be explained or if I could be directed to where it is futher explained, Thanks

Written very simple, but very powerful. Excellent write-up I would say. Urges me to continue reading.

Nice article, the language is very simple and everyone can understand it. Thanks!

hello,

how could you create another instance of gimli object in a arry form such as: gimli[0][β€œweapon”]…,gimli[1]["weapon]…?

thank you

Simple and straightforward. Thanks.

Really great article. One thing I’m struggling with is if I have two objs and I use the for … in loop to iterate through say obj2 to verify if any properties in obj2 aren’t in/but should be in obj1, how i would add the obj2 property to obj1. … in doing so, i want to add the obj2 key and value to obj1

eg. function extend(obj1, obj2) { for(var key in obj2) { if(!obj1[key]) { …

you really have a nice way in Explaining things , keep it up . this is an awesome tut.

Excellent and well written. Thank you!

Why can we not use β€˜.’ notation for accessing elements in the for…in loop?

πŸ‘ Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow β€” whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Β© 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.