How to correctly iterate through shipMisses
array to see if it contains the nested array with the specific values [2, 4]
(the dName
variabe)?
Here is my code:
shipMisses.includes(dName) // shipMisses = [[0, 1], [2, 4]]
// dName = [2, 4]
2
Answers
You can use the callback function for comparison. Here is an example:
You can use the
Array#some
element to check if at least one element is:Using the same
array
method you may also check by iteration to see if at least one element is:every
element of this array equals the corresponding element in the given array