Features
Solutions
Who uses Directual and why?
What can be built on the platform?
What industries benefit from Directual?
Learn
We all know that no-code development aims to simplify the process of creating applications without traditional coding techniques. One of the tools that no-code developers use is Lodash β a JavaScript library with functions that make working with arrays, objects, and functions a breeze. This lesson explains how to use the Lodash JavaScript library for sorting arrays in Directual.

Let's say you have an array link that you created using the Find object step, and now you need to sort this array and make a list that contains the following information in a specific order:
The Find object step allows you to search for objects in different data structures. It also can:
Let's use a data structure called Users as an example. It has only three fields:

Now letβs create a new data structure and name it My_struct. This data structure also has three fields:

Data structure fields configuration

A typical example of an object
Now you need a scenario to do all the heavy lifting for you.

Create a new Scenario. Next, in the Edit object step, select the Users_to_display structure. Enable Coding Mode and type the following expression:
_.sortByAll([ {{#user_ids}} { name: "{{name}}", age: {{age}} }, {{/user_ids}} Β ], ["age"]).map(function(i) { return i.name + ' β ' + i.age + ' years old' }).join(',')
Please note that we don't need double quotes around {{age}}, because the value is number. Following the JS-notation we don't quote numbers and booleans.
This expression allows you to apply the sortByAll method to the array, then collect an array of strings, and, finally, with the help of the join function, to convert a JS array into a Directual array.

Please note! Directual is only compatible with Lodash version 3.10.1.

Important! Don't forget that arrays and array links in a Directual database are strings, where the elements must be separated by a comma. To convert a JS array to a Directual array, use the .join(",") function, and the split(",") function to convert it back_._
Okay, now run the object through the scenario. Glorious, isn't it?

You can also use templating for the array to make it look even nicer:


You can use the sortByOrder method to change the order in which items are sorted:

Use `desc` - for sorting in descending order and `asc` - for sorting in ascending order.
The expression shall look like this:
_.sortByOrder([ {{#user_ids}} { name: "{{name}}", age: {{age}} }, {{/user_ids}} Β ], ["age"], ["desc"]).map(function(i) { return i.name + ' β ' + i.age + ' years old' }).join(',')

This is how the result looks now
There's a lot of cool stuff you can do with Directual and Lodash. Go ahead, experiment! If you get stuck, don't hesitate to ask for help in our No-code Community. Also, check out our 101 crash course to learn more about Directual and its features.