Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to reverse a string in JavaScript using reduce function

const reverseString = (str) => {
    return str.split('').reduce((acc, currItem)=> currItem + acc, '');//acc is accumulator
};

reverseString('hello world!');
// => !dlrow olleh
Source by attacomsian.com #
 
PREVIOUS NEXT
Tagged: #reverse #string #JavaScript #reduce #function
ADD COMMENT
Topic
Name
5+3 =