Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

how to get last two characters from string

Avatar

Level 2


In dialog of the componenet im going to author field it is like tag field

json data look as below 

"Icon" : "india:delhi/NR" ,

in htl when i try print  
icon: ${properties.icon}   // its coming full tag like    india:delhi/NR

But i want to print NR only

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @user96222 

You can use custom scripting:

var string = "StringABC";
var last2Char = string.slice(-2);

console.log(last2Char);

View solution in original post

1 Reply

Avatar

Level 6

Maybe something like this - before you write it as JSON set the variable first.

 

const str = '${properties.icon}';

const last2 = str.slice(-2);

Avatar

Correct answer by
Level 2

Hi @user96222 

You can use custom scripting:

var string = "StringABC";
var last2Char = string.slice(-2);

console.log(last2Char);