0
Can someone tell me how this code is working?
2 Answers
0
1. Create list of ages
2. Select element to add solution document.getElementById("demo") this is paragraph.
3. With innerHtml it assign solution to this element,you can type all of this in one line
4. ages.filter(some function) will loop trought array and do filtering and return new array with all data passed some filtering "test". This function you type yourself
5. Filtering function: it will get age (ages[0], then ages[1]...) so age is item of array and is changing with each iteration, looping is done by filter method.
So inside function it check is age greater or equal to 18 if so it return value, when every iteration complete filtered array is send to element.innerHtml = filteredArray and visible to screen
0
- So filter method is array method, many times you need to convert things to array to use it(like to check each letter of string)
- It will loop and return filtered array.
- It need to have function, mostly arrow function is used but normal function can also be used.
This function do checking, mostly have some if/else, and ofcourse need to return this value