I need to loop through all the columns retrieved from Google Sheets and find out their names and values through a code block like this:
data = _input.all()
for item in data:
row = item["json"]
for column_name, value in row.items():
print(f"Столбец: {column_name}")
print(f"Значение: {value}")
But I got an error saying _input doesn’t exist. So how do I loop through all the column names and their values?
_input is Python syntax. If you’re getting “_input doesn’t exist”, you’re likely in JavaScript mode. Check the Language dropdown at the top of the Code node. In JavaScript, the equivalent is $input.all().
print() won’t show output. The Code node requires you to return items. print() output goes nowhere.
Here’s a working version in JavaScript (Run Once for All Items):
const results = [];
for (const item of $input.all()) {
for (const [columnName, value] of Object.entries(item.json)) {
results.push({ json: { columnName, value } });
}
}
return results;
Or if you do switch to Python mode (requires Task Runners, enabled by default in 2.0+):
results = []
for item in _input.all():
for column_name, value in item.json.items():
results.append({"json": {"column_name": column_name, "value": value}})
return results