[Solved] How to check if array keys exist in multidimensional array?


Copy the arrays to new arrays, so that you can sort them, then compare each item in the arrays:

var a1 = winArray[0].slice(0);
var a2 = Xarray.slice(0);

var equal = a1.length == a2.length;
if (equal) {
    a1.sort();
    a2.sort();
    for (var i = 0; i < a1.length; i++) {
        if (a1[i] != a2[i]) {
            equal = false;
            break;
        }
    }
}

Demo: http://jsfiddle.net/Guffa/oa11qc4r/


If you mean that you want to search the array for a match, and not only compare the array at index 0, you would loop through the array and compare each array:

var a1 = Xarray.slice(0);
a1.sort();

var equal = false;
for (var j = 0; !equal && j < winArray.length; j++) {
    var a2 = winArray[j].slice(0);

    equal = a1.length == a2.length;
    var index = j;
    if (equal) {
        a2.sort();
        for (var i = 0; i < a1.length; i++) {
            if (a1[i] != a2[i]) {
                equal = false;
                break;
            }
        }
    }
}

Demo: http://jsfiddle.net/Guffa/oa11qc4r/1/

2

solved How to check if array keys exist in multidimensional array?