Hello I need help.
I had a simple code that checked if a word was in a list.
I used it a long time ago on the n8n, but when I needed to use it again it didn’t work.
Can someone help me.
The code is:
const wordInput = “{{ $json.body.message[0].message.conversation }}”; // Replace “example” with the word you want as input
const wordlist = [“example”, “other”, “word”, “list”]; // Define your word list
function checkWordInList(word, list) {
for (const wordList of list) {
if (wordList === word) {
return 2; // If the word is in the list, returns 2
}
}
return 1; // If the word is not in the list, returns 1
}
const result = checkWordInList(wordInput, listOfWords);
return {
json: {
result: result
}
};