File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -400,6 +400,21 @@ function tableHelper.isEmpty(inputTable)
400
400
return false
401
401
end
402
402
403
+ --- Retrieve a key associated with a specific value within a table.
404
+ ---
405
+ --- @param inputTable table The table to search within.
406
+ --- @param searchValue string | number The value to search for within the table.
407
+ --- @return string | number | false The key associated with the searchValue if found , or false if not found.
408
+ --- Note: This function is intended to handle situations where the loaded key may not align with the expected key due to the behavior of "cjson."
409
+ function tableHelper .getEntryKeyByValue (inputTable , searchValue )
410
+ for key , value in pairs (inputTable ) do
411
+ if key == searchValue or tostring (key ) == tostring (searchValue ) then
412
+ return key
413
+ end
414
+ end
415
+ return false
416
+ end
417
+
403
418
-- Check whether the table is an array with only consecutive numerical keys,
404
419
-- i.e. without any gaps between keys
405
420
-- Based on http://stackoverflow.com/a/6080274
You can’t perform that action at this time.
0 commit comments