Contenuti del Corso
JavaScript Data Structures
JavaScript Data Structures
2. Fundamentals of JavaScript Objects
Understanding Objects in JavaScriptCreating Objects in JavaScriptWorking with Nested Object PropertiesChallenge: Create and Structure an ObjectAccessing Object Properties in JavaScriptChallenge: Retrieve Object Property ValuesManaging Object PropertiesChallenge: Modify and Extend an ObjectDefining Object MethodsUsing Properties within MethodsChallenge: Work with Object MethodsFundamentals of JavaScript Objects Sum-Up
3. Advanced Object Manipulation Techniques
Iterating Over Object Properties with the for...in LoopChallenge: Explore Object Properties with IterationUsing hasOwnProperty() to Check Object PropertiesChallenge: Object Property Iteration with hasOwnProperty()Cloning and Merging Objects with the Spread OperatorChallenge: Combine Objects with the Spread OperatorDestructuring Objects for Cleaner CodeChallenge: Extract Data with Object DestructuringAdvanced Object Manipulation Sum-Up
4. Mastering JavaScript Arrays
Understanding JavaScript ArraysChallenge: Access Array ElementsModifying Arrays and Accessing ElementsChallenge: Modify Array ElementsIterating Over Arrays with the for LoopChallenge: Loop Through Arrays with forUsing the for...of Loop for Array IterationChallenge: Efficient Array Iteration with for...ofMastering JavaScript Arrays Sum-Up
5. Advanced Array Methods and Transformations
Transforming Arrays with the map() MethodChallenge: Modify Array Elements Using map()Filtering Arrays with the filter() MethodChallenge: Select Specific Data Using filter()Finding Elements in an Array with the find() MethodChallenge: Search for Items Using find()Sorting Arrays with the sort() MethodChallenge: Sort and Extract Data with sort()Advanced Array Methods and Transformations Sum-UpCourse Summary
Challenge: Retrieve Object Property Values
Task
You're given an object, user
, representing a person's hobbies and interests. Your task is to access and retrieve specific details from the object.
Access and log the person's name.
Access the
indoor
hobby and log it to the console.Store the person's age in a variable.
Access the favorite music genre and log it.
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(___); // person's name // Task 2 console.log(___); // indoor hobby // Task 3 const userAge = ___; console.log(userAge); // person's age // Task 4 console.log(___); // music genre
Expected output:
python
Use dot notation to access properties within an object.
To access properties within nested objects and arrays, chain the dot notation and square brackets (if needed).
Use assignment with dot notation to store property values in variables.
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(user.name); // person's name // Task 2 console.log(user.hobbies.indoor); // indoor hobby // Task 3 const userAge = user.age; console.log(userAge); // person's age // Task 4 console.log(user.preferences.music); // music genre
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 2. Capitolo 6