Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Chaining Array Methods 3:37
- Method Chaining 1 objective
- Working with Objects in Arrays 7:40
- Working with Objects 1 objective
- Combining filter() and map() 4:13
- Combining filter() and map() 1 objective
- Combining filter() and reduce() 4:42
- Combining filter() and reduce() 1 objective
- Nested Data and Additional Exploration 7:25
- Array Flattening 1 objective
- Nested Data 1 objective
Well done!
You have completed JavaScript Array Iteration Methods!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Because the map method returns an array, you can call another array method directly after it. The same is true for the filter method. This is commonly called chaining methods, because each call is like a link in a chain.
Snippets from the Video
const arr = [1,2,3];
const smallerArr = arr.filter(number => number !== 2);
const incrementedArr = smallerArr.map(number => number + 1);
console.log(incrementedArr); // => [2,4]
Removing Duplicates from an Array
To remove duplicate elements from an array, we can use filter(). Remember, the filter method provides three parameters to our callback function: the current element being processed in the array, the index of the current element being processed in the array, and the array filter() was called upon.
We can compare the index of the current element to the index of the current element in the array that filter() was called upon to determine if we've already encountered that element value. This works because the indexOf method will return the index of the first occurrence that is found in the array. So, indexes of duplicate elements will not equal the index of the first occurrence of their values.
const numbers = [1, 1, 2, 3, 4, 3, 5, 5, 6, 7, 3, 8, 9, 10];
const unique = numbers.filter(function(number, index, array) {
return index === array.indexOf(number);
});
console.log(unique); // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Rick S
11,273 Points4 Answers
-
Bert Witzel
Full Stack JavaScript Techdegree Graduate 27,918 Points1 Answer
-
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 Points2 Answers
-
<noob />
17,063 Points0 Answers
-
nfs
35,526 Points1 Answer
-
Teri Dent
11,515 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up