54
Views
11
Comments
Solved
How to reverse string using Javascript
Question

How to reverse string using Javascript also how to assign it in output

2016-04-22 00-29-45
Nuno Reis
 
MVP
Solution

Hello.


Everyone here is giving the exact same answer. Turns string into array and reverse the array.

But because of encoding, some characters take a combination of two characters. Like emojis or non-ASCII languages.

TLDR: split.reverse.join works for "Hello World", but fails for "👋🌍". You most never reverse the order of those or they turn into unreadable �� � � .


This is a mission for Intl.Segmenter, a JavaScript API for language-sensitive text segmentation. It breaks text into meaningful units like graphemes*, words, or sentences.


OS supports this so you can just use the following code in your JS widget:

const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });$parameters.out =  [...segmenter.segment($parameters.in)].map(segment => segment.segment).reverse().join("");



* A grapheme is the smallest unit of a writing system that represents a meaningful character to the reader.

2025-01-23 09-22-22
ABHIJITH G
Champion

Hi @Shivani More,
You can refer to the below js.

Here,

  • Split the string into an array of characters using .split('').
  • Reverse the array using .reverse().
  • Join the array back into a string using .join('').

Thanks

UserImage.jpg
Shivani More

Hi,

Thanks for help

2023-11-22 10-51-50
Jozy Sohail

Hi Shivani,

you can use the below JS to reverse the string

$parameters.ReversedString = $parameters.String.split('').reverse().join('');

hope it helps.


2021-11-12 04-59-31
Manikandan Sambasivam

Hi,

Please check the link below

https://www.outsystems.com/forums/discussion/71296/how-can-i-reverse-text/

2022-12-30 07-28-09
Navneet Garg

there are lots way to reverse the string in javascript

Reverse a String With Built-In Functions

function reverseString(str) {    return str.split("").reverse().join("");}reverseString("hello");

Reverse a String With Recursion

function reverseString(str) {  return (str === '') ? '' : reverseString(str.substr(1)) + str.charAt(0);}reverseString("hello");

easiest way is Reverse a String With Built-In Functions

https://personal-u1aragiz.outsystemscloud.com/FileViewerDemo/Reverse




FileViewerDemo.oml
2024-01-04 09-21-21
Venkatesaiya
2026-02-16 05-51-10
Sahana K

Hi,
Please find the attached oml, and demo


Thanks,
sahana

Reverese.oml
2016-04-22 00-29-45
Nuno Reis
 
MVP
Solution

Hello.


Everyone here is giving the exact same answer. Turns string into array and reverse the array.

But because of encoding, some characters take a combination of two characters. Like emojis or non-ASCII languages.

TLDR: split.reverse.join works for "Hello World", but fails for "👋🌍". You most never reverse the order of those or they turn into unreadable �� � � .


This is a mission for Intl.Segmenter, a JavaScript API for language-sensitive text segmentation. It breaks text into meaningful units like graphemes*, words, or sentences.


OS supports this so you can just use the following code in your JS widget:

const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });$parameters.out =  [...segmenter.segment($parameters.in)].map(segment => segment.segment).reverse().join("");



* A grapheme is the smallest unit of a writing system that represents a meaningful character to the reader.

2025-02-10 08-07-05
Sudha Narayanan

Hi @Shivani More ,

Refer this OML,


Thanks,

Sudha Narayanan

Reversestring Using Javascript.oml
2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Shivani More ,

I notice you have marked every single reply as solution.  

It is possible that sometimes more than 1 reply have the correct solution and have a similar quality, so that can happen, but EVERY reply, means that the value of the solution stamp is gone, a future reader can't use this to quickly scan the replies.

In light of the explanation by @Nuno Reis , that one seems to be the more complete, and less fragile one, so I would like to suggest that you unmark all the others.

Dorine

2023-03-24 11-55-45
Pawan Purohit

Hi,

Below I have given you a javascript function which will reverse the String 

function reverseString(str) {    return str.split("").reverse().join(""); }

let input = "Hello, World!";
let output = reverseString(input);

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.