Hie Everyone.I’m busy designing a small UI for the Palindrome Checker under the Javascript Algorithms And Data Structures section.However i have encountered a small challenge.I’m struggling to understand why the variable “textFormatted” changes on the second output.Any ideas/suggestions? I need to maintain the original "textFormatted’ after the code block.The identical code snippet is as follows.
//Breaking down string into an array
let textValue = "This is a test";
const regex = /[^a-z]+/gi;
let textFormatted = ((textValue.replace(regex, "")).toLowerCase()).split('');
console.log(textFormatted);
//Outputs [ 't', 'h', 'i', 's', 'i', 's', 'a', 't', 'e', 's', 't' ]
let textReversed = textFormatted.reverse();
console.log(textFormatted);
//Outputs [ 't', 's', 'e', 't', 'a', 's', 'i', 's', 'i', 'h', 't' ]