How to check if there is a value in a dictionary

Hello! I want to check if there is a specific value in a dictionary

local values = {
		[1] = {'firstSkill', 'secondSkill'}
	}

i tried with this but nothing happens:
if values[charValue.Value]['firstSkill'] then

any help?
(charValue is equal to 1)

Notice that each key in your dictionary is an array and not a dictionary, so to access values in that table, you would need to use indexes, for e.g:

print(values[1][1]) --> "firstSkill"

You can use that to check if firstSkill exists in the table [which in this case, represents a value for each key in your dictionary].

Is there a way to use the name instead of the number?

local values = {
	[1] = {
          ['firstSkill'] = something;
    }
}

You could do it like this if you want to use text as an index, turning the table into a dictionary

Edit: if you meant [1] at the start, you could use a string for that too.

2 Likes

If your value was a dictionary too, you’d have used the name of the thing you wanted, for e.g:

local values = {
		[1] = {
           ["firstSkil"] = "SuperPower",
        }
	}

Then, to call it, you’d do this -

print(values[1]["firstSkill"]
2 Likes