Fix example code on filter method to avoid confusion
parent
a24e76675a
commit
7b69f5f648
|
@ -322,10 +322,10 @@
|
|||
"The <code>filter</code> method is used to iterate through an array and filter out elements where a given condition is not true.",
|
||||
"<code>filter</code> is passed a callback function which takes the current value (we've called that <code>val</code>) as an argument.",
|
||||
"Any array element for which the callback returns true will be kept and elements that return false will be filtered out.",
|
||||
"The following code is an example of using filter to remove array elements that are not even numbers:",
|
||||
"The following code is an example of using <code>filter</code> to remove array elements that are equal to five:",
|
||||
"Note: We omit the second and third arguments since we only need the value",
|
||||
"<code>array = array.filter(function(val) {</code>",
|
||||
"<code> return val % 2 === 0;</code>",
|
||||
"<code> return val !== 5;</code>",
|
||||
"<code>});</code>",
|
||||
"Use <code>filter</code> to remove all elements from <code>array</code> that are greater than 5."
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue