Expand my Community achievements bar.

Dive in, experiment, and see how our AI Assistant Content Accelerator can transform your workflows with personalized, efficient content solutions through our newly designed playground experience.
SOLVED

Array

Avatar

Level 3

Can anyone help me with how to collect the first two elements of an array in AJO (Handlebars.js) and store them in two different fields?


{% let demo = "1,903~19.03" %}
{% let array = split(demo, "~") %}

{% let val1 = array[0] %}
{% let val2 = array[1] %}

val1 :{{ val1 }}
val2: {{ val2 }}

I am using this, but I am getting an error.

Output:-

val1 :false
val2: false

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Ajo_WisdomChase 

Some time I love regex to solve situations like this.

 

{% let demo = "1,903~19.03~1213" %}
{% let first = regexGroup(demo,"^([0-9,\\.]+)~([0-9,\\.]+)", 1) %}
{% let second = regexGroup(demo,"^([0-9,\\.]+)~([0-9,\\.]+)", 2) %}
{{first}}
{{second}}

 

~cheers,

NN

View solution in original post

3 Replies

Avatar

Employee

You can take a look at this related thread https://experienceleaguecommunities.adobe.com/t5/journey-optimizer-questions/get-last-item-of-a-list... 

 

{% let demo = "1,903~19.03" %}

Second part
{% let idx = indexOf(demo,"~" ) + 1 %}
{%= substr(demo, idx, length(demo)) %}

First part
{% let idx = indexOf(demo,"~" )  %}
{%= substr(demo, 0, idx) %}

Avatar

Correct answer by
Community Advisor

@Ajo_WisdomChase 

Some time I love regex to solve situations like this.

 

{% let demo = "1,903~19.03~1213" %}
{% let first = regexGroup(demo,"^([0-9,\\.]+)~([0-9,\\.]+)", 1) %}
{% let second = regexGroup(demo,"^([0-9,\\.]+)~([0-9,\\.]+)", 2) %}
{{first}}
{{second}}

 

~cheers,

NN

Avatar

Administrator

Hi @Ajo_WisdomChase,

Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!



Sukrity Wadhwa