5. Javascript Objects Part 2
5. Javascript Objects Part 2
pk
unioffaisalabad
Aasma Khalid
Lecturer
The University of Faisalabad
Arrays and Array Methods www.tuf.edu.pk
unioffaisalabad
• JavaScript provides a number of built-in methods for manipulating arrays. Some of the most commonly used
array methods are:
METHODS
• for loop - This is the most basic way to iterate through an array.
The for loop uses a counter variable that is incremented on
each iteration. For example, the following code will print out
each element in the array:
www.tuf.edu.pk
unioffaisalabad
• Map - The map method is used to create a new array with the
result of a callback function called on each element in the
original array. The callback function takes one argument, the
current element, and returns the new value for that element.
For example, the following code will return an array of each
element multiplied by 2:
www.tuf.edu.pk
unioffaisalabad
• JavaScript's Date object allows you to work with dates and times in
your scripts. It can be used to get the current date and time, or to
manipulate and format dates and times in various ways.
• Creating a new Date object is simple. You can either create a new
date object with the current date and time by calling new
Date() with no arguments, or you can create a date object with a
specific date and time by passing in a string or numerical values.
• Here's an example of how you can use the Date object to get the
current date and time:
Math www.tuf.edu.pk
unioffaisalabad