Ways to get values form function

Hi folks,
I’d like to know how many ways we can get the values from a function:

Hey @tuliovargas,

That looks like a rather neat image you have put together, is it from a training program somewhere?

If you do console.log(items[0].json); and check the browser dev console when running it will show you the objects you can use and should help you find the answer.

This might be helpful.

There is a website called http://jsonselector.com

Which lets you to generate selectors visually from the JSON. So you can get idea about how to pick the child objects.

Your function node should look something like:

const data = items[0].json;

const grape = data.fruits[0].name
const grape2 = data.fruits[1].name

const reducer = (previousValue, currentValue) => previousValue + parseInt(currentValue.amout, 10);

const grape_amount = data.fruits.reduce(reducer, 0)

//pupulate array with all fruits
const fruits = data.fruits;

const city = data.city

const delivery =  data.delivery

return [
  {
    json: {
      grape,
      grape2,
      grape_amount,
      fruits,
      city,
      delivery
    }
  }  
]
Example workflow

Hi @tuliovargas,

If you’re looking for all the different ways you can reference an input field in the function node, I’d point you towards the expressions documentation — everything there can be used in the function node too.