---
author: PUT YOUR NAME HERE
copyright: Niall Kader
title: Arrays Review
---

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
array.push method pushes data to the end of an array
#### explain the parameters of the push() method here
the parameters are items that are to be added to the target array
#### explain what the push() method returns (if not undefined)
the 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 newArray = [1,2,3,4];
console.log(newArray.push(5)); // returns the new length of 5

const oldArray = ["Steve","John","Greg","Paul"];
console.log(oldArray.push("Harold")); // returns the new length of 5
```


## includes()
#### put your description of the includes() method here
array.includes searches for an entry in the array that matches the condition you describe
#### explain the parameters of the includes() method here
the first parameter is the value that you search for, the second one is optional and is the starting index
#### explain what the includes() method returns (if not undefined)
the method returns a boolean depending on if the search was successful
#### put one or two of your own code samples that demonstrate the includes() method here
```js
const newArray = [1,2,3,4];
console.log(newArray.includes(5)); // would return false

const oldArray = ["Steve","John","Greg","Paul"];
console.log(oldArray.includes("Greg")); // would return true
```


## concat()
#### put your description of the concat() method here
conjoining two arrays into a single array
#### explain the parameters of the concat() method here
the method is extended from a defined array, the parameters within the method are the arrays that are to be combined with the original
#### explain what the concat() method returns (if not undefined)
the method returns the contents of the joined arrays
#### put one or two of your own code samples that demonstrate the concat() method here
```js
const a1 = [1,3,5,7];
const a2 = [2,4,6,8];
console.log(a1.concat(a2)); // returns [1,3,5,7,2,4,6,8]
```


## join()
#### put your description of the join() method here
combines data from an array into a single variable
#### explain the parameters of the join() method here
no parameters are required, however if you want to set a character to separate each data point you can specify that in parenthesis
#### explain what the join() method returns (if not undefined)
returns a string
#### put one or two of your own code samples that demonstrate the join() method here
```js
const a1 = [1,3,5,7];
console.log(a1.join(" & ")); // returns "1 & 3 & 5 & 7"
```


## pop()
#### put your description of the pop() method here
removes the last element of an array
#### explain the parameters of the pop() method here
none
#### explain what the pop() method returns (if not undefined)
the removed element
#### put one or two of your own code samples that demonstrate the pop() method here
```js
const a1 = [1,3,5,7];
console.log(a1.pop()); // returns 7
```


## 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
required: takes a function, parameters are the current element.
optional: index of current element, array of current element
#### explain what the find() method returns (if not undefined)
the method returns the value of the first element that passes the test
#### put one or two of your own code samples that demonstrate the find() method here
```js
const a1 = [1,3,5,7];
console.log(a1.find(7)); // returns 7
```


## splice()
#### put your description of the splice() method here
splice method adds and/or removes array elements
#### explain the parameters of the splice() method here
requires the index of the element to remove or add, the number of items removed represented as "count", and if adding elements, specify them here
#### explain what the splice() method returns (if not undefined)
the method returns an array of removed items
#### put one or two of your own code samples that demonstrate the splice() method here
```js
const oldArray = ["Steve","John","Greg","Paul"];
console.log(oldArray.splice(2, 1)); // would return "Greg"
```


## slice()
#### put your description of the slice() method here
returns selected elements in an array as a new array
#### explain the parameters of the slice() method here
takes a start index and end index
#### explain what the slice() method returns (if not undefined)
returns selected elements in an array as a new array
#### put one or two of your own code samples that demonstrate the slice() method here
```js
const oldArray = ["Steve","John","Greg","Paul"];
console.log(oldArray.slice(2, 3)); // would return ["Greg", "Paul"]
```


# Part 2

## filter()
#### put your description of the filter() method here
creates a new array filled with elements that pass a test provided by a function
#### explain the parameters of the filter() method here
a function, provided with a current element, and optionally, the index of the current element and, the array of the current element
#### explain what the filter() method returns (if not undefined)
creates a new array filled with elements that pass a test provided by a function
#### put one or two of your own code samples that demonstrate the filter() method here
```js
const targetArray = ["tier1-tree1","tier1-tree2","tier2-tree1","tier2-tree2"];
console.log(targetArray.filter(element => element.includes("tier1"))); // would return ["tier1-tree1","tier1-tree2"]
```


## map()
#### put your description of the map() method here
creates a new array from calling a function for every array element
#### explain the parameters of the map() method here
a function, provided with a current element, and optionally, the index of the current element and, the array of the current element
#### explain what the map() method returns (if not undefined)
creates a new array
#### put one or two of your own code samples that demonstrate the map() method here
```js
const targetArray = [
    {section:"tier", amount:3},
    {section:"tree", amount:3},
    {section:"level", amount:3},
];
console.log(targetArray.map(element => element.section)); // would array of ["tier","tree","leve"]
```


## reduce()
#### put your description of the reduce() method here
the method executes 
#### explain the parameters of the reduce() method here
a function, provided with a total value, current value, and optionally, the index of the current element and, the array of the current element, and outside of the function, an initial value to start
#### explain what the reduce() method returns (if not undefined)
returns the total or 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 a1 = [1,2,3,4,5,6,7,8,9,10];
console.log(a1.reduce((sum,num) => sum + num, 0)); // returns the total
```