Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (9.5k points)

Below is the JavaScript code I’ve to convert the String to an array in order to reverse a String backwards. Can anyone tell me is there a direct way of doing this? 


<!DOCTYPE html>

<html lang="en">


        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta http-equiv="X-UA-Compatible" content="ie=edge">




        String manipulation with 

        <pre id="target">w3resource</pre>

        <script src="script.js"></script>



var word = document.getElementById('target');

var arr = Array.from(word.innerText);


var newArr = []

function rearrangement(arr1, arr2)


    for(var i = 9; i < arr1.length; i--)


    return arr2


console.log(rearrangement(arr, newArr))

1 Answer

0 votes
by (19.7k points)

Instead of converting the String to an array, you can use the reverse() method like below:


Interested in Java? Check out this Java Certification by Intellipaat.    

Related questions

0 votes
1 answer
asked May 7, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
0 votes
1 answer
asked Feb 19, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories