How to: Set Object Values Using Lodash

Overview

When using Unqork, you might want to create or change the values of an object. To do that, use the _.create and _.set Lodash functions.

To read more about the parameters of the _.create and _.set Lodash functions, visit: https://lodash.com/docs/4.17.15.

In this example, you'll use the _.create and _.set Lodash functions to create and alter your object path and value. First, you'll create an object using the _.create function. Next, you'll use end-user input to alter the key/value pair of your object using the _.set function to set the path, or key, and value of your created object. Then, your module outputs the new key/value pair to the end-user.

Here are the basic steps for this example:

1. Your Calculator component creates a new object.
2. The end-user enters their key and value to hardcode into the object.
3. The object's key/value pair is hardcoded with the end-user's input.
4. The new object values display to the end-user.

Here's how the comnfiguration looks in the Module Builder:

A static image displaying the set object values with Lodash use case in the UDesigner module builder.

Here’s how the configuration looks in Express View:

A static image displaying the set object values with Lodash use case in Express View.

 

Resources