There are many additional built-in array methods, a complete list of which is on the MDN’s Array iteration methods page.
The documentation for each method contains several sections:
- A short definition.
- A block with the correct syntax for using the method.
- A list of parameters the method accepts or requires.
- The return value of the function.
- An extended description.
- Examples of the method’s use.
- Other additional information.
In the instructions below, there are some errors in the code. Use the documentation for a given method to determine the error or fill in a blank to make the code run correctly.
Instructions
In the code editor, there is an array called words
. We want to create a new array of interesting words. The first thing we want to do is check if there are words that are fewer than 6
characters long. There is something missing in the words.some()
method call. Fix this method so that true
is printed to the console.
For more information browse MDN’s documentation on .some()
.
The .some()
method returned true
, which means there are some words in the array that are shorter than six characters. Use the .filter()
method to save any words longer than 5
characters to a new variable called interestingWords
, declared with const
.
We’ve used .filter()
in a previous exercise, but, for more information browse MDN’s documentation on .filter()
.
In the last line of main.js, there is this code:
// console.log(interestingWords.every(word => ));
Complete the code between the parentheses to check if every element has more than 5 characters.
Make sure to uncomment (delete the //
before) the last line of the program before you run the code.
For more information browse MDN’s documentation on .every()
.