MarkLogic 10 and Data Hub 5.0

Latest MarkLogic releases provide a smarter, simpler, and more secure way to integrate data.

Read Blog →


Stay On Top Of Everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up →


Part 2: What’s New with JavaScript in MarkLogic 10?
Posted by Dermot Smyth on 08 February 2020 05:10 PM

V8 Engine Upgrade in MarkLogic 10

In this continuation of the series, What’s New with JavaScript in MarkLogic 10?, we’ll discuss in detail about the new API’s the V8 Engine upgrade comes with. In the previous blog, we mentioned how MarkLogic 10 comes with a ton of new features, some of which include:

  1. The addition of JavaScript Modules, also known as MJS — which was discussed in detail in the previous blog.
  2. The V8 Engine was upgraded from version 5.3 to version 6.7. This is the actual motor that ‘powers’ JavaScript in MarkLogic.
  3. Additional features from the ECMAScript 2015 JavaScript standard have been added. Go to to find out what you can do with ECMAScript 2015.

Now I’ll take a deep dive into some of the new methods I have found most useful in my work.

String Utility Methods

Some new utility methods have been added to string, including padStart() and padEnd(). For example:

let stringToPad = "7";

stringToPad.padStart(3 , "0"); // -> '007'

stringToPad.padEnd(3 , "0"); // -> '700'

Similarly, there is trimStart() and trimEnd():

let stringToTrim = " hello world ";

stringToTrim.trimStart(); // -> 'hello world '

stringToTrim.trimEnd(); // -> ' hello world'

Object Functions

Another useful feature in the new V8 Engine is that there are now a object values() function. In MarkLogic 9, we had the Object.keys()function, which returned the property names of a given object. However, if you wanted to get the values of the properties in an object — say a person JSON object — you were forced to do something like this:

const person = { 
   firstName: 'Michael' , 
   lastName: 'Knight' 


// --> ["Michael", "Knight"]

With MarkLogic 10, we can use Object.values() function to do the same thing:

const person = {

  firstName: 'Michael' ,
  last Name: 'Knight'


.map(([key, value])
    => key + ":" + value.toUpperCase());

//-> ["firstName=Michael", "lastName=Knight"]

Another useful function that was added is Object.entries(), which  allows you to iterate the actual property-value pairs inside a JavaScript object. For example:

const person = {
  firstName: 'Michael',
  last Name: 'Knight'

.map(([key, value])
    => key + ":" + value.toUpperCase());

//-> ["firstName=Michael", "lastName=Knight"]

These new functions allow you to write more concise code when compared to MarkLogic 9.

Internationalization Library

The upgrade also provides more features for the internationalization library. Firstly, we can specify explicitly how we want a date formatted. In the example below, we specify how we want to display a French formatted date:

let date = DATE.UTC(2019, 11, 17, 15, 0, 42);
let formatter = new Intl.DateTimeFormat('fr-fr', {
  weekday: 'long',
  year: 'numeric', 
  month: 'numeric', 
  day: 'numeric', 
  hour: 'numeric',
  minute: 'numeric',
  second: 'numeric',

//-> mardi 17/12/2019 à 16:00:00:42

The result contains the name of the day of the week followed by the date and time. If you want to take this result and parse particular parts of it, like the week, day, or time, you would have to do a bit more work using string manipulation to display that on a GUI. To make this a little less complicated, the function formatToParts() can be used. For example:


     "type": "weekday",
     "value": "mardi"
     "type": "literal",
     "value": " "
     "type": "day",
     "value": "17"
     "type": "literal",
     "value": "/"

So instead of having the date returned as a string, we get an array of objects containing the formatted date in parts. This makes using the individual parts of the date information easier.

Next Steps

We just had a brief look at the new APIs that came with the V8 Engine upgrade in MarkLogic 10 (and how you can use them). If you would like to review over the differences between Server-side JavaScript (SJS) and JavaScript Module (MJS) scripts, read the previous blog in the series, JavaScript Modules in MarkLogic 10.

In the next blog in the series, we will discuss another piece of functionality that was included in the upgrade, Object Rest and Spread Properties, and how they can be used in your Data Hub code.

The post Part 2: What’s New with JavaScript in MarkLogic 10? appeared first on MarkLogic.

Comments (0)