Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Objects | Section
JavaScript Essentials for React Native Development

bookObjects

Swipe um das Menü anzuzeigen

Objects in JavaScript are used to store collections of data as key-value pairs. Each key is a string (or symbol), and each value can be any data type, including numbers, strings, arrays, or even other objects. You use objects when you want to represent a single entity with various properties, such as a user with a name, age, and membership status.

1234567891011121314151617181920
// Creating an object with key-value pairs const user = { name: "Alice", age: 28, isMember: true }; // Accessing properties using dot notation console.log(user.name); // "Alice" // Accessing properties using bracket notation console.log(user["age"]); // 28 // Updating a property user.age = 29; console.log(user.age); // 29 // Adding a new property user.email = "alice@example.com"; console.log(user.email); // "alice@example.com"
copy

Arrays and objects are both used to group data, but they serve different purposes:

  • Arrays are ordered lists accessed by numeric indices and are ideal for collections of similar items, such as a list of names;
  • Objects, on the other hand, are unordered and use named keys, making them better for representing structured data where each value is associated with a specific property name.

To access or update object properties, you can use either dot notation (object.property) or bracket notation (object["property"]). Dot notation is more concise and commonly used when the property name is a valid identifier. Bracket notation is useful when the property name is dynamic or not a valid identifier.

question mark

Which of the following statements about JavaScript objects is true?

Wählen Sie die richtige Antwort aus

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 8

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Abschnitt 1. Kapitel 8
some-alt