0

I have an element i want to search for in the format of [numOne, numTwo]. i want to be able to search through an array called movesTaken two find this element.

lets assume this:

let numOne = 0;
let numTwo = 1;

let movesTaken = [[0,1],[5,8],[3,2],[4,7],[8,3],[9,8],[5,4],[1,1],[4,4],[3,9],[1,43],[23,6]];

what i've tried to do is achieve a true or false value by using .includes() by using the below code

movesTaken.includes([numOne,numTwo]);

and ive also tried

movesTaken.includes([0,1]);

neither of these options seem to work and only output false, how would i go about testing if these exist in the array? will this leave me with no choice but to use a for loop to loop through each individual sub-array and their individual values?

1
  • See this answer from the duplicate Commented Sep 20, 2020 at 4:56

1 Answer 1

0

The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.

The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

I think you can use something like this

let array = [0, 1];
let movesTaken = [[0,1],[5,8],[3,2],[4,7],[8,3],[9,8],[5,4],[1,1],[4,4],[3,9],[1,43],[23,6]];
let check = movesTaken.some(a => array.every((v, i) => v === a[i]));

console.log(check);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.