I want to check if the JSON has a “date” and a “totalDuration”.
If it has both entries, the date should be returned.
If it has only one or none of the entries, an empty string should be returned.
What is wrong with the code that it does not work?
const event = $input.all();
let date = "";
for (const item of event) {
if (item.json.date && item.json.totalDuration)
{
date = item.json.date;
break;
}
}
return {result: date};
Information on your n8n setup
- n8n version: [email protected]
- Running n8n via (n8n cloud):