some : if it finds an array element where the function returns a true value, some() returns true (and does not check the remaining values). includes : for all element is return .
Don't know right or not ?. When use some or includes ?. Thankyou everyone.
some() The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false.
indexOf() The Array#indexOf() function is a common alternative to includes() . The indexOf() function returns the first index in the array at which it found valueToFind , or -1 otherwise.
The difference is in the output. find will return the value, some will return a boolean .
some
takes in a callback function where you can write your own logic to determine if an array contains some element which matches the conditions you wrote.
includes
does a generic equalTo comparison on every element and will return true if at least one element in the array is equal to the value to find.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With