Reverse a String in TypeScript Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Reversing a string involves changing the order of its characters, so the last character becomes the first, and vice versa. In TypeScript, there are various methods to achieve this, depending on the developer's preference and the specific requirements of the task. Table of Content Using a LoopUsing Array Methods (reverse,split and join)Using reduceMethod 1: Using a LoopThis method utilizes a loop to iterate through the characters of the string in reverse order, building the reversed string. It is a more traditional approach and may be preferred in scenarios where simplicity and explicit control over the iteration are desired. Example: In this example, a string "Geeks For Geeks" and is reversed using the a loop. JavaScript function reverseStringUsingLoop(str: string): string { let reversed = ''; for (let i = str.length - 1; i >= 0; i--) { reversed += str[i]; } return reversed; } const reversedStringLoop = reverseStringUsingLoop('Geeks For Geeks'); console.log(reversedStringLoop); Output: skeeG roF skeeGMethod 2: Using Array Methods (reverse,split and join)This method leverages the array functions split, reverse, and join to convert the string into an array of characters, reverse the array, and then join it back into a string. It is a concise and readable approach that takes advantage of the built-in array methods. Example: In this example, a string "Geeks For Geeks" and is reversed using the array methods. JavaScript function reverseStringUsingArray(str: string): string { // Convert the string to an array // of characters, reverse it, //and join back to a string return str.split('').reverse().join(''); } const reversedStringLoop = reverseStringUsingArray('Geeks For Geeks'); console.log(reversedStringLoop); Output: skeeG roF skeeGMethod 3: Using reduceThis method employs the reduce function to accumulate the reversed string. It iterates through the characters of the string, prepending each character to the accumulating reversed string. Example: In this example, a string "Geeks For Geeks" and is reversed using the reduce method. JavaScript function reverseStringUsingReduce(str: string): string { // using reduce with split functions return str.split('') .reduce((reversed, char) => char + reversed, ''); } const reversedStringReduce = reverseStringUsingReduce('Geeks For Geeks'); console.log(reversedStringReduce); Output: skeeG roF skeeG Comment More infoAdvertise with us Next Article Reverse a String in TypeScript J jaykush Follow Improve Article Tags : JavaScript Web Technologies TypeScript Similar Reads How to Remove Spaces from a String in TypeScript ? TypeScript offers various inbuilt functions to remove spaces from a string. These functions can be used to remove spaces between characters or entire words. Below, we explore different approaches to remove spaces from a string in TypeScript.Table of ContentUsing split() and join() methodsUsing repla 4 min read TypeScript String In TypeScript, the string is sequence of char values and also considered as an object. It is a type of primitive data type that is used to store text data. The string values are used between single quotation marks or double quotation marks, and also array of characters works same as a string. TypeSc 4 min read How to reverse a string in R Reversing a string means changing its order so that the last character becomes the first, the second last character becomes the second, and so on. A while loop is a control flow statement used in R programming to execute a block of code repeatedly as long as a specified condition is true. By using a 4 min read TypeScript String repeat() Method In TypeScript the repeat() method helps in generating a new string by replicating the original string up to a certain number of iterations. It's an inbuilt method of TypeScript as well as JavaScript. Syntaxstring.repeat(count: number): string;Parameters:count: No. of times you want to repeat the str 1 min read Iterate Over Characters of a String in TypeScript Iterating over characters of a string involves going through them one by one using loops or specific methods. This is useful for tasks like changing or analyzing the content of a string efficiently. Example:Input: string = "Hello Geeks"; Output: H e l l o G e e k sBelow listed methods can be used to 4 min read TypeScript String indexOf() Method The indexOf() method in TypeScript is an inbuilt function used to find the index of the first occurrence of a specified value within a calling string. If the value is not found, it returns -1.Syntaxstring.indexOf(searchValue[, fromIndex]) Parameter: This method accepts two parameters as mentioned ab 2 min read TypeScript | String lastIndexOf() Method The lastIndexOf() is an inbuilt function in TypeScript which is used to get the index within the calling String object of the last occurrence of the specified value. Syntax: string.lastIndexOf(searchValue[, fromIndex]) Parameter: This method accepts two parameter as mentioned above and described bel 1 min read TypeScript String substring() Method The substring() is an inbuilt function in TypeScript that returns the subset of a String object. It takes two parameters: indexA (starting index) and optional indexB (ending index, non-inclusive). It returns the portion of the string between these indices.Syntaxstring.substring(indexA, [indexB]) Par 2 min read TypeScript Array reverse() Method The Array.reverse() method in TypeScript is used to reverse the elements of an array in place, modifying the original array. It rearranges the elements such that the first element becomes the last, the second element becomes the second-to-last, and so on.Syntax:array.reverse(); Parameter: This metho 2 min read TypeScript String charAt() Method The String.prototype.charAt() method in TypeScript is used to return the character at the specified index of a string. The characters in the string are indexed from left to right, starting at 0.Syntax:string.charAt( index )Parameter: This method accepts a single parameter as mentioned above and desc 2 min read Like