Conteúdo do Curso
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
Mastering JavaScript Arrays Sum-Up
Arrays are data structures used to store and manipulate collections of values.
Creating Arrays
- Arrays in JavaScript are created using square brackets
[]
and are known as array literals; - Commas separate elements within the array.
// Array literal creation
const colors = ["red", "green", "blue"];
const numbers = [1, 2, 3, 4, 5];
// Arrays with different data types
const mixedArray = ["apple", 42, true, { name: "John" }];
Accessing Array Elements
- Array indices start at
0
, meaning the first element has an index of0
, the second element has an index of1
, and so on; - Specific elements within an array can be accessed by using square brackets with the element's index.
const firstColor = colors[0]; // "red"
const secondNumber = numbers[1]; // 2
Modifying Array Elements
Array elements can be changed by accessing them through their index and assigning a new value.
colors[1] = "yellow";
numbers[0] = 10;
Array Length
The length
property of an array represents the number of elements it contains. It automatically adjusts when elements are added or removed.
const colorsCount = colors.length; // 3
const numbersCount = numbers.length; // 5
Finding the Last Element
To retrieve the value of the last element in an array, we can calculate its index using the array's length, which is array.length - 1
.
const lastColor = colors[colors.length - 1];
const lastNumber = numbers[numbers.length - 1];
For Loop
- The
for
loop is used for iterating over an array element by element; - It uses a loop counter variable (e.g.,
i
) to access each element by index; - The loop continues as long as the counter is less than the array's length;
- It's a fundamental tool for array iteration.
for (let i = 0; i < numbers.length; i+=1) {
console.log(numbers[i]);
}
For...of Loop
- The
for...of
loop is a more modern and concise way to iterate over arrays; - It automatically handles the loop counter and provides direct access to each element's value;
- It simplifies array iteration, making the code cleaner and more readable.
for (const color of colors) {
console.log(color);
}
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 4. Capítulo 9