---
author: Jonah Faas
date: 1/30/26
copyright: Niall Kader
title: Arrays Review
description: Arrays review homework
---

Create a sample page and experiment with the array methods listed below.
Come up with a few very simple code samples for each of them.

Then fill in the details for each of the methods below.
I have done the first one for you (the foreach() method) to demonstrate 
what I expect you to do with the other methods listed.

## forEach()
The forEach method is used to loop through the array.
There are two parameters that you can pass into forEach().
Only the first one is required:
1. a **callback** function.
These are the parameters that you can define for the callback (only the first parameter is required):
	1. The **current elmeent**
	1. The **index** of the current element
	1. The **array** that you are looping through
1. a value/object to be used as **this**, which is usually not useful.

JavaScript will loop through the array and invoke the callback for each element in the array,
passing in the parameters described above.

Here's an example:
```js
const scores = [94, 85,9 7];
scores.forEach((ce)=> console.log(ce))
```

Here's an example that uses the index parameter in the callback:
```js
scores.forEach((ce, index)=>{
	console.log("INDEX: " + index, "CURRENT ELEMENT (a score): " + ce);
});
```

# Part 1

## push()
put your description of the push() method here
push() puts any number of items on to the end of an array as long as they are seperated by a comma

explain the parameters of the push() method here
the parameters are the items to be added to the array

explain what the push() method returns (if not undefined)
the push() method returns the new length of the array

put one or two of your own code samples that demonstrate the push() method here
```js
const scores = [94, 85, 9, 7];
let newScores = scores.push(4, 2);
```







## includes()
put your description of the includes() method here
includes() searches the array for the value entered in and will return true if it is there and false if it isnt
explain the parameters of the includes() method here
the parameters are the element being searched for and optionally the start value
explain what the includes() method returns (if not undefined)
it returns true if the value is found and false if it isn't
put one or two of your own code samples that demonstrate the includes() method here
```js
const scores = [94, 85, 9, 7];
let scoreMaybe = scores.includes(9);
```



## concat()
put your description of the concat() method here
concat() joins 2 or more strings together
explain the parameters of the concat() method here
the string being joined to the string having the method called on it is required and any other strings must be joined with a comma
explain what the concat() method returns (if not undefined)
the return value is a new string containing the combined strings
put one or two of your own code samples that demonstrate the concat() method here
```js
let text1 = "Hello";
let text2 = "World!";
let text3 = text1.concat(" ", text2);
```

## join()
put your description of the join() method here
join() returns an array as a string does not change the original array
explain the parameters of the join() method here
parameters are the seperator
explain what the join() method returns (if not undefined)
the array values seperated by the specified seperator
put one or two of your own code samples that demonstrate the join() method here
```js
const scores = [94, 85, 9, 7];
let newScores = scores.join(" ");
```

## pop()
put your description of the pop() method here
pop() removes the last element in the array changes the original array
explain the parameters of the pop() method here
no paramaters
explain what the pop() method returns (if not undefined)
the returned value is the removed item
put one or two of your own code samples that demonstrate the pop() method here
```js
const scores = [94, 85, 9, 7];
let lastScore = scores.pop();
```

## find()
put your description of the find() method here
returns the value of the first element that passes a test
explain the parameters of the find() method here
function() is required to run for each array element
currentvalue is required to return the value of the current element
index is option al to show the index of the current element
arr is optional to return the array of the current element
explain what the find() method returns (if not undefined)
the value of the first element to the pass the test
put one or two of your own code samples that demonstrate the find() method here
```js
const scores = [94 ,85 ,9 ,7];
let firstSmall = scores.find((ce, i, arr) => s < 80);
```

## splice()
put your description of the splice() method here
splice() adds or removes array elements and overrites the original array
explain the parameters of the splice() method here
index is required to declare the position to add or remove items
count is optional to count how many items to remove
itemlist is optional to add any elements
explain what the splice() method returns (if not undefined)
the return value is the array containing any removed items
put one or two of your own code samples that demonstrate the splice() method here
```js
const scores = [94, 85, 9, 7];
let newArray = scores.splice(1, 2, 37, 23);
```


## slice()
put your description of the slice() method here
slice() returns selected item elements in an array as a new array without overriting the original array
explain the parameters of the slice() method here
start is optional to declare the start position
end is optional to declare the end position
explain what the slice() method returns (if not undefined)
the return value is the array containing the selected elements
put one or two of your own code samples that demonstrate the slice() method here
```js
const scores = [94, 85, 9, 7];
let newArray = scores.slice(1,2);
```



# Part 2

## filter()
put your description of the filter() method here
filter() creates a new array with items from the original array that pass a test
explain the parameters of the filter() method here
function() is required to run for each array element
currentValue is required for the value of the current element
index is optional for the index of the current element
arr is optional for the array of the current element
explain what the filter() method returns (if not undefined)
return value is the array created from the elements that pass the test
put one or two of your own code samples that demonstrate the filter() method here
```js
const scores = [94, 85, 9, 7];
let newArray = scores.filter((ce, i, arr) => s < 80);
```

## map()
put your description of the map() method here
map() creates a new array after calling a function on each element in the array without destroying the original array
explain the parameters of the map() method here
function() is required to run for each array element
currentValue is required for the value of the current element
index is optional for the index of the current element
arr is optional for the array of the current element
explain what the map() method returns (if not undefined)
the return value is the array after the function has been called on each of the elements
put one or two of your own code samples that demonstrate the map() method here
```js
const scores = [94, 85, 9, 7];
let newArray = scores.map((ce, i, arr) => Math.sqrt);
```

## reduce()
put your description of the reduce() method here
reduce() executes a reducer function for an element in an array
explain the parameters of the reduce() method here
function() is required to run for each array element
total is required to declare the initalValue or the previously returned value of the funtion
currentValue is required to hold the value of the current element
currentIndex is optional to hold the index of the current element
arr is optional to hold the array the current element belongs to
explain what the reduce() method returns (if not undefined)
the return value is the accumulated result from the last call of the function
put one or two of your own code samples that demonstrate the reduce() method here
```js
const scores = [94, 85, 9, 7];
let initalValue = 0;
let sum = scores.reduce((t, num, i, arr) => t + num, initalValue, scores[0]);
```
