The CreatorCon Call for Content is officially open! Get started here.

Amit Gujarathi
Giga Sage
Giga Sage

ServiceNow JavaScript tutorials String functions | ServiceNow javascript Examples on string function

Hi All,
I hope you're doing great.


In today's tutorial, we will be looking into various Javascript string functions which can be of great use in our day-to-day ServiceNow development activity.
In this ServiceNow javascript tutorial, we will try to look into various Javascript string functions along with examples for the same.

 

What is String in JavaScript?
The JavaScript string is an object that represents a sequence of characters.

There are 2 ways to create strings in JavaScript

  • By string literal
  • By string object (using the new keyword)


The functions which will be explained in this tutorial are as given below :

  • charAt(): It provides the char value present at the specified index.
  • charCodeAt(): It provides the Unicode value of a character present at the specified index.
  • concat(): It provides a combination of two or more strings.
  • indexOf(): It provides the position of a char value present in the given string.
  • lastIndexOf(): It provides the position of a char value present in the given string by searching for a character from the last position.
  • Search(): It searches a specified regular expression in a given string and returns its position if a match occurs.
  • match(): It searches a specified regular expression in a given string and returns that regular expression if a match occurs.
  • replace(): It replaces a given string with the specified replacement.
  • substr(): It is used to fetch the part of the given string based on the specified starting position and length.
  • substring(): It is used to fetch the part of the given string based on the specified index.
  • slice(): It is used to fetch the part of the given string. It allows us to assign positive as a well negative indexes.
  • toLowerCase(): It converts the given string into a lowercase letter.
  • toLocaleLowerCase(): It converts the given string into a lowercase letter based on the host's current locale.
  • toUpperCase(): It converts the given string into an uppercase letter.
  • toLocaleUpperCase() It converts the given string into an uppercase letter based on the host's current locale.
  • toString(): It provides a string representing a particular object.
  • valueOf(): It provides the primitive value of a String object.
  • split(): It splits a string into a substring array, then returns that newly created array.
  • trim(): It trims the white space from the left and right sides of the string.

 

Please be sure to bookmark this article as well as mark it as Helpful if you thought it was helpful.

 

Regards,

Amit Gujarathi

Technomonk Youtube 

Amit Gujarathi Linkedin 

TheTechnomonk.com 

ServiceNow Community Amit Gujarathi 

Comments
bakers
Tera Contributor

Could you explain why the string.padStart function doesn't seem to work in ServiceNow?

Example to run in the background script editor:

var myval = '67';
var zeropad = myval.padStart(8, '0');

gs.info(myval);
gs.info(zeropad);
gs.info('done');

 

Execution results in display of "undefined" for zeropad

*** Script: 67

*** Script: undefined

*** Script: done

 

Version history
Last update:
‎11-26-2023 07:43 PM
Updated by:
Contributors