> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/build/work-with-data/reference-data/link-data-items/accessing-linked-items-in-the-code-node.md).

# Accessing linked items in the Code node

Every item in a node's input data links back to the items used in previous nodes to generate it. This is useful if you need to retrieve linked items from further back than the immediate previous node.

To access the linked items from earlier in the workflow, use `("<node-name>").itemMatching(currentNodeinputIndex)`.

For example, consider a workflow that does the following:

1. The Customer Datastore node generates example data:

   ```json
   [
   	{
   		"id": "23423532",
   		"name": "Jay Gatsby",
   		"email": "gatsby@west-egg.com",
   		"notes": "Keeps asking about a green light??",
   		"country": "US",
   		"created": "1925-04-10"
   	},
   	{
   		"id": "23423533",
   		"name": "José Arcadio Buendía",
   		"email": "jab@macondo.co",
   		"notes": "Lots of people named after him. Very confusing",
   		"country": "CO",
   		"created": "1967-05-05"
   	},
   	...
   ]
   ```
2. The Edit Fields node simplifies this data:

   ```json
   [
   	{
   		"name": "Jay Gatsby"
   	},
   	{
   		"name": "José Arcadio Buendía"
   	},
       ...
   ]
   ```
3. The Code node restores the email address to the correct person:

   ```json
   [
   	{
   		"name": "Jay Gatsby",
   		"restoreEmail": "gatsby@west-egg.com"
   	},
   	{
   		"name": "José Arcadio Buendía",
   		"restoreEmail": "jab@macondo.co"
   	},
   	...
   ]
   ```

The Code node does this using the following code:

{% tabs %}
{% tab title="JavaScript" %}

```js
for(let i=0; i<$input.all().length; i++) {
	$input.all()[i].json.restoreEmail = $('Customer Datastore (n8n training)').itemMatching(i).json.email;
}
return $input.all();
```

{% endtab %}

{% tab title="Python" %}

```python
for i,item in enumerate(_input.all()):
	_input.all()[i].json.restoreEmail = _('Customer Datastore (n8n training)').itemMatching(i).json.email

return _input.all();
```

{% endtab %}
{% endtabs %}

You can view and download the example workflow from [n8n website | itemMatching usage example](https://n8n.io/workflows/1966-itemmatching-usage-example/).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/build/work-with-data/reference-data/link-data-items/accessing-linked-items-in-the-code-node.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
