Skip to main content

reverseString

The reverseString() function reverses a string.

Parameters​

ParameterTypeDescription
strStringThe string to reverse.

Returns​

  • String: The reversed string

Throws​

  • Error: If the str is not a valid string

Example​

const utils = require('utils-core.js');
const str = 'hello world';
const reversed = utils.format.reverseString(str);
console.log(reversed);
// 'dlrow olleh'
const utils = require('utils-core.js');
const str = '123456';
const reversed = utils.format.reverseString(str);
console.log(reversed);
// '654321'