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

bookObjects

Desliza para mostrar el menú

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?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 8

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Sección 1. Capítulo 8
some-alt