It is not printing anything[Solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
20th Jul 2022, 10:46 PM
Varin
Varin - avatar
4 Answers
+ 2
Line 9: Incorrect implementation for .filter() callback function .filter() accepts a callback function, that can accept up to 3 arguments (the 2nd and 3rd are rather rarely used). The callback function returns a boolean expression that .filter() use to decide whether an element be included in the resulting array, or not. Callback function arguments (in order) 1st - the element 2nd - index of element represented by 1st argument 3rd - the array itself So call to .filter() may be in any of these forms .filter( element => ... ); .filter( ( element, index ) => ... ); .filter( ( element, index, array ) => ... ); The problem at line 9 is, the callback function uses 1st argument, named <num>. But the callback function doesn't evaluate <num>. It instead evaluates whether `actors.networth > 10`. Obviously 'networth' is an unknown attribute to <actors>. Thus `actors.networth > 10` always evaluates to false (being undefined) let actor = actt.filter(num => num.networth > 10)
21st Jul 2022, 6:11 AM
Ipang
+ 2
You can try with the actors index name and actor index networth. console.log(actors[0].name +'' +actors[1].networth);
21st Jul 2022, 4:06 AM
Chris Coder
Chris Coder - avatar
+ 1
Ipang Thanks man it worked
21st Jul 2022, 9:10 PM
Varin
Varin - avatar
0
Chris Coder yep i know but i'm learning filter method now so i want to applay the filter method on the object
21st Jul 2022, 4:10 AM
Varin
Varin - avatar