Expand my Community achievements bar.

Applications for the 2024 Adobe Target Community Mentorship Program are open! Click to the right to learn more about participating as either an Aspirant, to professionally level up with a new Certification, or as a Mentor, to share your Adobe Target expertise and inspire through your leadership! Submit your application today.
SOLVED

how to get last two characters from string

Avatar

Level 3


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

3 Replies

Avatar

Community Advisor

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);