---
title: JavaScript Processor
slug: litmusedge/javascript-processor
docTags: 
createdAt: 2024-08-06T19:05:02.892Z
---

The JavaScript Processor lets you write JavaScript in the Code Editor to add, remove, or modify fields in the message from an input tag.

## Why use the JavaScript Processor

Use this processor when you need to reshape a message beyond what a fixed processor supports, for example, renaming a field (such as changing `value` to `furnace pressure`), keeping only the fields you need and dropping the rest, deriving a new field from an existing value (such as adding an `error` field when `value` crosses a threshold), or reformatting a Unix timestamp into a human-readable one.

## How it works

Write your script in the Code Editor, which supports syntax highlighting and real-time validation. Learn more about JavaScript syntax on [W3Schools](https://www.w3schools.com/js/).

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/ISdwmzXAwwVLFUiWXqNO3_image.png" size="80" isUploading="false" width="766" height="690" darkWidth="766" darkHeight="690" position="flex-start" showCaption="false"}

From the editor, you can also access:

- **Playground**, to test, write, and validate your script in real time before deploying it.

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/blxh7gPWDxR9zAZlBwrfT_image.png" size="80" width="1918" height="964" position="flex-start" showCaption="false" indent="2" darkWidth="1918" darkHeight="964"}

- **Validate**, to check your code.

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/c0PPDqsXX8klBwb9ZmShI_image.png" size="80" width="767" height="406" position="flex-start" showCaption="false" indent="2" darkWidth="767" darkHeight="406"}

### Working with input messages

Every message from the input is stored in an array called `values`. Use a `for i, message in values{}` statement to loop over it: `message` holds the full incoming message for you to manipulate, and `i` identifies which connection wire it came from. For a single input, you can replace `i` with `_` since there's only one connection to distinguish. Both `i` and `message` are just variable names; you can name them whatever you like.

With multiple inputs, for example three connection wires named A, B, and C, `i` tells you which wire each message came from as the loop runs. Use if-else logic to manipulate each input differently, or apply the same manipulation to all of them. You can output the result for a single input only, or for all of them.

## Related topics

- [Use the JavaScript Processor Function](docId:9ynGGwCJ55vZ2dg8wsxa4)&#x20;

