If you have any query feel free to chat us!
Happy Coding! Happy Learning!
Arrays and objects are two fundamental data types in JavaScript used to store and manipulate collections of values.
An array is an ordered collection of values, where each value is identified by an index, starting from zero. We can use arrays to store a list of values of any data type, including strings, numbers, objects, and even other arrays. Arrays are represented using square brackets []
.
For example:
arduinoCopy code
const fruits = ['apple', 'banana', 'orange'];
const numbers = [1, 2, 3, 4, 5];
const mixed = ['apple', 1, { name: 'John', age: 30 }, true];
An object, on the other hand, is an unordered collection of key-value pairs, where each key is a unique string that identifies a value. We can use objects to store information about a single entity, such as a person or a product. Objects are represented using curly braces {}
.
For example:
cssCopy code
const person = {
name: 'John',
age: 30,
hobbies: ['reading', 'running'],
address: {
street: '123 Main St',
city: 'New York',
state: 'NY'
}
};
We can access the values stored in arrays and objects using dot notation or square bracket notation. In dot notation, we use the .
operator to access the value of a property or an element of an array. In square bracket notation, we use the []
operator and provide the index or key as a string.
For example:
cssCopy code
const fruits = ['apple', 'banana', 'orange'];
const person = {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'New York',
state: 'NY'
}
};
console.log(fruits[0]); // Output: 'apple'
console.log(person.name); // Output: 'John'
console.log(person.address['city']); // Output: 'New York'
Arrays and objects are powerful data types that can be combined to create complex data structures and algorithms.
Comments: 2
I am not able to access videos from second class and further. I have already completed first class
When will I get my course?
Now, Your query was resolved.