“@NApiVersion 2.x”To:
“@NApiVersion 2.1”It’s also worth mentioning that as of May 2020 SuiteScript 2.1 is not available for client scripts nor SuiteCloud Development Framework yet, so bear that in mind.
var i = 5; for (var i = 0; i < 10; i++) { // after last loop i equals 10 } // Here i is 10Using let:
let i = 5; for (let i = 0; i < 10; i++) { // after last loop i equals 10 } // Here i is 5For details check out w3schools.
var array = [1];Using “for in”:
for (let index in array){
let value = array[index];
//value equals 1
}
Using “for of”:
for (let value of array){
//value equals 1
}
This looks more elegant to me, but you be the judge. For details check out w3schools.var myString = "Hello world";Using search method:
var includesWorld = myString.search("world") != -1; //true
Using includes method:
var includesWorld = myString.includes("world"); //true
Amazing! Makes the code more readable. For details check out w3schools.var myArray = ["banana", "apple", "pear", "watermelon"];Using indexOf method:
var includesWatermelon = myArray.indexOf("watermelon") != -1; //true
Using includes method:
var includesWatermelon = myArray.includes("watermelon"); //true
For details check out w3schools.var guestAges = [17,18,21,22,24];
var allAdults = guestAges.every( function (age){ return age >= 18; } );
//allAdults equals false because one of the guest ages is under 18
For details check out w3schools.let myArray = [1,2,3,4,4,4,4,4,4,4,4,4,4,4,4,4,5]; let mySet = new Set(myArray); // mySet now equals {1, 2, 3, 4, 5} let deDuplicatedArray = Array.from(mySet); //deDuplicatedArray now equals [1,2,3,4,5]
let animals = new Set(); animals.add('pig'); animals.add('bear'); animals.add('cat'); animals.add('dog'); console.log(animals.size); // 4 animals.add('bear'); // Adding a duplicate console.log(animals.size); // Still 4!It has several methods you can use like: add, size, has, forEach, delete and clear so it makes a powerful tool by itself. Sets also outperforms Arrays so that's another reason to love it. For details check out Alligator.io and Mozilla Docs.
let array1 = ["bear", "wolf"];
let array2 = ["moose", ...array1 ];
//array2 equals ["bear","wolf","moose"]
Or making copies of arrays like:
let array1 = [1, 2, 3]; let array1Copy = array1; //This is a shallow copy let array1CopySpread = [...array1 ]; array1Copy.push(4); //Pushing to the shallow copy //array1 equals [1,2,3,4] //array1Copy equals [1,2,3,4] //array1CopySpread equals [1,2,3] //The copy using spread remains unmodifiedFor details and more uses check out Scotch.io and Mozilla Docs.
var myNumber = 23; var myString = `text line 1 text line 2 text with "double quotes" and 'single quotes' text with variable value of ${myNumber}`;
text line 1 text line 2 text with "double quotes" and 'single quotes' text with variable value of 23
function hello() { return "Hello World!"; }Arrow function:
hello = () => { return "Hello World!"; }And it can get even shorter:
hello = () => "Hello World!";
Anonymous arrow function with params:
((name)=> `Hello ${name}!`)('stranger'); //"Hello stranger!"
For details and more uses check out w3schools.
https.get.promise({ url: 'https://jsonplaceholder.typicode.com/todos/1' }) .then(function(response){ log.debug({ title: 'Response', details: response }); }) .catch(function onRejected(reason) { log.debug({ title: 'Invalid Get Request: ', details: reason }); })You can also create your own Promises now like so:
let promise = new Promise((resolve) => {
let response = https.get({url: 'https://jsonplaceholder.typicode.com/todos/1'});
resolve(response.body);
});
promise.then(log.debug); //This calls log.debug and uses whatever data is returned as parameter
For details and more uses check out Mozilla Docs.
async function asyncRequest(){ //<< Note the async keyword next to the function let promise = new Promise((resolve) => { let response = https.get({url: 'https://jsonplaceholder.typicode.com/todos/1'}); resolve(response.body); }); //promise.then(log.debug); //No longer using this let responseBody = await promise; //Using await instead log.debug('responseBody', responseBody); //Logs correctly }For details and more uses check out Mozilla Docs.
So what do you think? Do you agree with our list? Please share your comments below.