some Array Method | JavaScript Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the array sub method executes a given function on the elements of the array and returns true if the callback function returns a true T value for at least one element inside of the array if for all of the elements it will return a false value then the sum method will return false also let's see how that looks in code we have here the numbers array which has numbers from 1 to 5 and we want to check if at least one element is greater than 4 so for that we can write numbers that sum and here we can provide a callback function greater than 4 and this callback function gets the item the index and array which is called path but in this case you only want the item and we can return item greater than four now this will go over the array and it will check is this bigger than four now is this no is this and so on until it will find five which is greater than 4 which we return true and then the sum method will return true also so let's pass this as a callback function let's store the result and let's console eight so we can see what we get as we said it should return true if we didn't have five then this will return false because all of the elements inside the array are less than four less than or equal than four actually another use case for this sum method could be if for example we have an array of objects of people and we want to check if at least one person from this array is an adult all right let's do that so we are going to have here an array of objects this will be persons and here will have a name Korean age 25 and then let's get name van age 20 also let's set the comma there and let's add another one I am age 16 all right and now we want to create another callback function is adult which will get in the item so in this case the person and it can return person that age is greater than 17 or we can say greater equal than 18 like that now let's person this adult callback function save this and let's see what we messed up numbers is not defined because we now have persons let's also that clear days quickly alright and now we get through because two of the persons from our array are adult but if we change this to 15 and and for example now we get false alright I guess with these examples you can see how the sum method works I hope you enjoyed this tutorial and I'll see you in the next one bye [Music]
Info
Channel: Florin Pop
Views: 4,037
Rating: 4.9699249 out of 5
Keywords: javascript, javascript tutorial, javascript tutorial for beginners, array method, javascript arrays, higher order function, learn javascript, javascript array methods, some, javascript some, some array method, learn some, some HOF
Id: 0uDvZSlBOtA
Channel Id: undefined
Length: 3min 58sec (238 seconds)
Published: Fri Apr 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.