How can I find a string in a two dimensional array?
问题 I have an array that looks like this. var array[["a","b"],["c","d"],["e","f"]]; I want to be able to search through the array for the string "d" and return the corresponding value "c" . 回答1: try: function find_str(array){ for(var i in array){ if(array[i][1] == 'd'){ return array[i][0]; } } } EDIT: function find_str(array){ for(var i=0;i<array.length;i++){ if(array[i][1] == 'd'){ return array[i][0]; } } } 回答2: A general function for getting all the elements of the arrays that contain the