Function to Lookup Data in Separate/Previous Node

Describe the issue/error/question

Struggling to put together a function that queries the output of another function node to effectively “lookup” an item by a key value, and return the value of a separate key.

Desired Result:
Find item in JSON where value = “Action” and return id.

Note: All items in JSON will be unique (both by value and id).

Sample JSON:
[
{
“id”:1569,
“value”:“Action”,
“color”:“dark-blue”
},
{
“id”:1570,
“value”:“Adventure”,
“color”:“dark-blue”
},
{
“id”:1571,
“value”:“Indie”,
“color”:“dark-blue”
},
{
“id”:1572,
“value”:“RPG”,
“color”:“dark-blue”
},
{
“id”:1573,
“value”:“Simulation”,
“color”:“dark-blue”
},
{
“id”:1574,
“value”:“Strategy”,
“color”:“dark-blue”
},
{
“id”:1575,
“value”:“Early Access”,
“color”:“dark-blue”
},
{
“id”:1576,
“value”:“Massively Multiplayer”,
“color”:“dark-blue”
},
{
“id”:1577,
“value”:“Free to Play”,
“color”:“dark-blue”
},
{
“id”:1578,
“value”:“Racing”,
“color”:“dark-blue”
}
]

Hi @Blickman

Welcome to the community.

You do not have to write a function for this. n8n has nodes that can help you do this.
You can copy - paste the below workflow to your environment to see how I did it in this example.
The last Set node is just because you asked to return the Id, if you remove this you get all 3 values. Depends on your needs of course.

1 Like

Im actually looking to incorporate this into function node/code. Reason behind this as it ties into a much larger data transformation process. Just a small portion I am stuck on.

Hi @Blickman

Would this help?