@nhanh102 , your code has a few issues not to mention that you do not need to use Code node to achieve what you are looking for in the first place. However, assuming you have a reason to use Code node, here are the issues with your code.
The expression $input.first().json returns an object (!). Therefore, looking for it in the string is not valid. That is, text.includes(searchText) will never work.
The returned value has to be an array of objects (or just an object, which will be wrapped into an array automatically). However, you are trying to return a string with input[0].json.id. Thus, you are getting the error “Code didn’t return items properly”.
If you want to check if id’s value is in the string then you would need the include() method to have a string as its argument. That is, your searchText should have $input.first().json.id assigned.
Looks like you just want to return id. That could be achieved with return $input.first().
As I mentioned already, simply to check if id’s value is in the string, you do not need to use Code node. Depending on what you want to do next, IF node could be a better option. For example,
Actually, I am returning an id but want to check if it is in a list of ids. If so, return true to continue. But if you do it this way, in case it returns 1 but the string has 10101, it still returns true.
Yep, Actually, I am returning an id but want to check if it is in a list of ids. If so, return true to continue. But if you do it this way, in case it returns 1 but the string has 10101, it still returns true.