ShadowRanger24 50 Posted August 1, 2016 Hi everyone. So I'm having a bit of trouble finding a way to get a nested array via a certain value. Here's what the array looks like: _array = [ ["Key 1", [0, 0, 0], [0, 0, 0]], ["Key 2", [0, 0, 0], [0, 0, 0]], ["Key 3", [0, 0, 0], [0, 0, 0]] ]; I want to be able to get the array containing the value just by searching for the key. So for example I would like to get "["Key 1", [0, 0, 0], [0, 0, 0]]" just by searching for "Key 1". Does anyone know how I can do this? Perhaps there's an easier way I could approach this instead? Thanks in advance. Share this post Link to post Share on other sites
HallyG 239 Posted August 1, 2016 Hi everyone. So I'm having a bit of trouble finding a way to get a nested array via a certain value. Here's what the array looks like: _array = [ ["Key 1", [0, 0, 0], [0, 0, 0]], ["Key 2", [0, 0, 0], [0, 0, 0]], ["Key 3", [0, 0, 0], [0, 0, 0]] ]; I want to be able to get the array containing the value just by searching for the key. So for example I would like to get "["Key 1", [0, 0, 0], [0, 0, 0]]" just by searching for "Key 1". Does anyone know how I can do this? Perhaps there's an easier way I could approach this instead? Thanks in advance. _array = [ ["Key 1", [0, 0, 0], [0, 0, 0]], ["Key 2", [0, 0, 0], [0, 0, 0]], ["Key 3", [0, 0, 0], [0, 0, 0]] ]; _keyStr = "Key 1"; _key = _array select {(_x select 0) isEqualTo _keyStr} select 0; // Returns ["Key 1", [0, 0, 0], [0, 0, 0]] 1 Share this post Link to post Share on other sites
jshock 513 Posted August 1, 2016 _array = [ ["Key 1", [0, 0, 0], [0, 0, 0]], ["Key 2", [0, 0, 0], [0, 0, 0]], ["Key 3", [0, 0, 0], [0, 0, 0]] ]; _searchKey = "Key 1"; _matchedArray = []; { _keyArray = _x; if ((_keyArray select 0) == _searchKey) exitWith { { _matchedArray pushBack _x; } forEach _keyArray; }; } forEach _array; _matchedArray; Untested, but should work....but give you a concept. Forgot about the select command, use hallyGs post :D. 1 Share this post Link to post Share on other sites
ShadowRanger24 50 Posted August 1, 2016 Thanks for the help guys. Got it working. :) Share this post Link to post Share on other sites