How to check if Array Value == Word?

My Goal?

I want a FOR Loop to run through all the Values of an Array and check if any of those Values are Equal to a Specific Word.

So far, I’ve been able to print all the values of an array using this code:

Code:

local Input_Lower = string.lower(Answer_Input.Text)
local Split = string.split(Input_Lower,  " ")
		
for index, value in ipairs(Split) do
    print(value)
end

Output:

image

Now all I need is for the FOR Loop to run through these Values and check if it’s Equal to a Specific Word. How do I achieve this? :thinking:

use table.find() function nnnn

Are you trying to check if the strings combined equals something, or if one of them do? If only one, you can simply do:

or a table.find function would also work.

I’m not trying to find the value in the Array. I am trying to find if any of those values is equal to a specific word.

The value is the word. And then you loop through Split’ to check if any of the words are equal to the specific word, which in Sugar’s example is “thing”.

Edit:
But Sugar had an error

for index, value in ipairs(Split) do
    print(value)
    if value == "thing" then

    end
end
1 Like