I've seen a few other posts about this on Stack Overflow, but the answer always seems to be to create an object with key / value pairs. This doesn't seem to be what I need in my current situation. What I'm wanting to do: I have different arrays which could possibly contain a username. I want to check each array and see if the username is present as a value in them. If it is, I'd like a string representation of a name of the array variable. Example:
var array = ['apple', 'orange', 'grape'];
var array2 = ['apple', 'pear', 'plumb']
member_arrays = new Array();
// I'd like this block to be dynamic in that i don't have to specify the array name
// in the inArray or member_arrays[member_arrays.length+1] (just loop through my arrays
// and add a string representation of the array name to the member_arrays array)
if ($.inArray( 'apple', array ) != -1)
member_arrays[member_arrays.length] = 'array';
if ($.inArray( 'apple', array2) != -1)
member_arrays[member_arrays.length] = 'array2';
// etc...
if
block, and the code works as intended, using jQuery ($.inArray
), eg:if ($.inArray('apple', array) != -1) member_arrays.push('array');
– Rob W Nov 2 '11 at 16:39