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">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
String manipulation with
<pre id="target">w3resource</pre>
<script src="script.js"></script>
</body>
</html>
var word = document.getElementById('target');
var arr = Array.from(word.innerText);
console.log(arr)
var newArr = []
function rearrangement(arr1, arr2)
{
for(var i = 9; i < arr1.length; i--)
arr2.unshift(arr1.pop(i))
return arr2
}
console.log(rearrangement(arr, newArr))