I have a 2d array like this:
var arr = [[2,3],[5,8],[1,1],[0,9],[5,7]];
Each index stores an inner array containing the coordinates of some
Here's what I implemented
getIndexOfArray(array: any[], findArray: any[]): number{
let index = -1;
array.some((item, i)=>{
if(JSON.stringify(item) === JSON.stringify(findArray)) {
index = i;
return true;
}
});
return index;
}
here array
is the array in which we need the index and findArray
is the array whose index will be returned.
Note: This function will return only the first occurrence of findArray
array insight array
array.