Evaluating Javascript Arrays

Posted by FailBoy on Stack Overflow See other posts from Stack Overflow or by FailBoy
Published on 2010-04-07T12:18:07Z Indexed on 2010/04/07 12:23 UTC
Read the original article Hit count: 277

Filed under:
|
|

I have an array that contains an array of arrays if that makes any sense. so for example:

[[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]

I want to see whether an array exists withing the array, so if [1, 2, 3] is duplicated at all. I have tried to use the .indexOf method but it does find the duplicate. I have also tried Extjs to loop through the array manually and to evaluate each inner array, this is how I did it:

var arrayToSearch = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]];        
var newArray = [1, 2, 3];
Ext.each(arrayToSearch, function(entry, index){
                    console.log(newArray, entry);
                    if(newArray == entry){
                        console.log(index);
                    };
                });

This also does not detect the duplicate. the console.log will output [1, 2, 3] and [1, 2, 3] but will not recognize them as equal. I have also tried the === evaluator but obviously since == doesn't work the === wont work. I am at wits end, any suggestions.

© Stack Overflow or respective owner

Related posts about arrays

Related posts about JavaScript