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

This processor function enables users to use JavaScript as a programming language for manipulating and managing data coming from input tags.

# JavaScript Overview

- This processor uses JavaScript scripting
- **Simple Use case**: The output you receive from DeviceHub message or from Analytics, might not be helpful, and you want to change the name of a field within that message
  - In general, if you want to add, remove or modify ANY field in the input, this scripting processor is very useful
  - *e.g* Instead of "value" you want your data to show "furnace pressure"
  - *e.g* Instead of having all fields of the message, you only want to have "success", "deviceId" and "value" and skip everything else
  - *e.g* You want to add a custom field to the message, based on the "value" field, such as: if value = 2, "error": "overheating"
  - *e.g* You only want to change the timestamp to human readable format instead of Unix timestamp, but keep otherwise keep the message as-it-is
- **Single Input:** Every message from the input, is stored as an array called "values"
  - Using "for i, message in values\{}" statement, allows to access this input and manipulate it
  - Here "i" represents what is the *definition* defined in the connection wire, more useful for multi-inputs, to identify and distinguish between each inputs, so for single input, "i" can be replaced with "\_"
  - "message" contains the entire message in the input, and you can perform your manipulations to this "message" parameter
  - **Note:** "i" and "message" can be any custom variable name
- **Multiple Input:** Suppose you have 3 different inputs attached to this scripting processor, with the connecting wires named A, B and C
  - "for i, message in values\{}" will now have 3 inputs
  - "i" represents from which connection wire is the input coming from
  - with if-else statements, every input can be manipulated in isolation, or a common manipulation can be applied to all inputs
  - You can choose to output "result" only for one input, or all of the inputs

# JavaScript Parameters

| **Parameters** | **Details**                                                                                      |
| -------------- | ------------------------------------------------------------------------------------------------ |
| Text Editor    | Write the JavaScript code you want to execute. Learn more [here](https://www.w3schools.com/js/). |

![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/krYjpPahBjD-Rv0wijxlU_image.png)

:::hint{type="info"}
**Note:&#x20;**&#x57;hen creating an analytics flow with *JavaScript Processor&#x20;*&#x70;rocessor, refer the [Use the JavaScript Processor Function](docId\:inGtSivG5iq_FlCZlhXws) guide for more details.
:::

