I have an array, that happens to be filled with arrays: [[1, "thing"], [2, "other thing"], [3, "still other thing"]] I want to be able to select a value inside one of the arrays without having to make the array a temporary variable and then pick the item. Can this be done?
            Asked
            
        
        
            Active
            
        
            Viewed 44 times
        
    0
            
            
         
    
    
        Jonathan Spirit
        
- 569
- 3
- 7
- 14
1 Answers
2
            You can index into a nested array with the same '[]' syntax.
var arr = [[1, "thing"], [2, "other thing"], [3, "still other thing"]];
console.log(arr[0]); // [1, "thing"]
console.log(arr[0][0]); // 1
For reference, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
In that link search for two-dimensional
 
    
    
        mrk
        
- 4,999
- 3
- 27
- 42
- 
                    Oh, that's perfect. I can't believe I hadn't thought of that. – Jonathan Spirit Jul 27 '14 at 14:35