N/util Module

We can use this module to verify the objects, arrays, boolean, date, function, number, regular expressions, strings. This module also can use to get the nanoseconds time. And also to extend an object or merge objects can also possible using this module. This module provides a provision to iterate in objects and arrays.

Sample code

var array = [1, 2, 3];
var isArray = util.isArray(array); // return true

var obj1 = {
'key1':'value 1'
};

var obj2 = {
'key2':'value 2'
};

var obj3 = {
'key3':'value 3'
};
util.extend(obj1, obj2);
/*OUTPUT
obj1={
'key1':'value 1',
'key2':'value 2'
}*/
util.extend(obj1, obj3);
/*OUTPUT
obj1={
'key1':'value 1',
'key2':'value 2',
'key3':'value 3'
}*/

// to get the time difference in nanoTime
  var dateNow = new Date();
  var startTime = util.nanoTime(dateNow);
  var endTime = util.nanoTime(new Date()) 
  var difference= startTime-endTime;
// OUTPUT
it will return the time difference in nanoseconds

Leave a comment

Your email address will not be published. Required fields are marked *