0% found this document useful (0 votes)
3 views

javascriptlesson4

This document covers JavaScript Lesson 4, focusing on objects, arrays, and methods. It explains the definition and manipulation of objects and arrays, including accessing and modifying their properties and elements. Additionally, it introduces common array methods such as push, pop, shift, and unshift.

Uploaded by

vanguyen103
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

javascriptlesson4

This document covers JavaScript Lesson 4, focusing on objects, arrays, and methods. It explains the definition and manipulation of objects and arrays, including accessing and modifying their properties and elements. Additionally, it introduces common array methods such as push, pop, shift, and unshift.

Uploaded by

vanguyen103
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

JavaScript Lesson 4: Objects, Arrays, and Methods

Page 1: Introduction to Objects in JavaScript

 What is an Object?

o In JavaScript, an object is a collection of properties and values.

o Objects allow you to group related data and functionality in a single structure.

Example:

Accessing Object Properties:

 You can access object properties using dot notation or bracket notation.

Example:

console.log(person.name); // Outputs: Alice

console.log(person['age']); // Outputs: 25

Modifying Object Properties:

 You can add or change properties in an object dynamically.

Example:

Page 2: Methods in Objects


 What is a Method?

o A method is a function that is a property of an object.

Example:

The this Keyword in Methods:

 In a method, this refers to the object calling the method.

Example:

Page 3: Introduction to Arrays

 What is an Array?
o An array is a collection of ordered values. Arrays are used to store multiple values in a
single variable.

Example:

Accessing Array Elements:

 You can access array elements using their index (starting from 0).

Example:

Modifying Arrays:

 You can modify arrays by adding, removing, or changing elements.

Example:

Page 4: Array Methods

 Common Array Methods:

o push(): Adds a new element to the end of the array.

o pop(): Removes the last element from the array.

o shift(): Removes the first element from the array.

o unshift(): Adds a new element to the beginning of the array.

Example:

You might also like