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

JS4 ClassNotes

The document provides an overview of arrays in JavaScript, including how to create arrays, access elements using indices, and various array methods such as push, pop, concat, and splice. It also includes practice questions for calculating average marks and applying discounts to item prices. Additionally, it offers exercises for manipulating an array of company names.

Uploaded by

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

JS4 ClassNotes

The document provides an overview of arrays in JavaScript, including how to create arrays, access elements using indices, and various array methods such as push, pop, concat, and splice. It also includes practice questions for calculating average marks and applying discounts to item prices. Additionally, it offers exercises for manipulating an array of company names.

Uploaded by

rashidk
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Arrays in JS

Collections of items

Create Array

let heroes = [ “ironman”, “hulk”, “thor”,

“batman” ]; let marks = [ 96, 75, 48, 83,

66 ];

let info = [ “rahul”, 86, “Delhi” ];


Arrays in JS
Array Indices

arr[0], arr[1],
arr[2] ....

0 1 2 3 4
Looping over an Array
Print all elements of an
array
Let‘s Practice
Qs. For a given array with marks of students -> [85, 97, 44,
37, 76, 60] Find the average marks of the entire class.
Let‘s Practice
Qs. For a given array with prices of 5 items -> [250, 645, 300, 900, 50]
All items have an offer of 10% OFF on them. Change the array to store
final price after applying offer.
Arrays in JS
Array Methods

Push( ) : add to
end

Pop( ) : delete from end &


return

toString( ) : converts array to


string
Arrays in JS
Array Methods

Concat( ) : joins multiple arrays &


returns result

Unshift( ) : add to
start

shift( ) : delete from start &


return
Arrays in JS
Array Methods

Slice( ) : returns a piece of the array

slice( startIdx, endIdx )

Splice( ) : change original array (add, remove,


replace)

splice( startIdx, delCount, newEl1... )


Let‘s Practice
Qs. Create an array to store companies -> “Bloomberg”, “Microsoft”, “Uber”, “Google”,
“IBM”, “Netflix”

a.Remove the first company from the array

b.Remove Uber & Add Ola in its place

c.Add Amazon at the end

You might also like