Looking for matches in multi-dimensional arrays inJavascript

Viewed 66

I am trying to match entire arrays in Javascript. I have a userInput array and I need to find a matching array within a multi-dimensional array and output the match.

var t1 = [0,0,0];
var t2 = [1,0,0];
var t3 = [0,0,1];
var userInput = [0,0,0];
var configs = [t1, t2, t3];

I am trying to find a way to match userInput to one of the other arrays and output the matching array. With underscore.js I can find a match one at a time without looping, but that returns a bool.

var result = _.isEqual(userInput,t1) returns true

I need to find the matching array inside the configs array. I can nest loops to go through configs, but I can't figure out how to match it to userInput.

5 Answers
Related