XML make string lowercase and replace words from arrays

Faced with a problem, tried to parse an XML document and replace the appropriate words to those that are in my array, decided to automate it and no idea what to do next. I’ve looked through a lot of information on this subject, but I haven’t found the right answer.


const fs = require("fs")
const xmlParser = require("xml2json")
const formatXml = require("xml-formatter")

const wordReplacement = [ ["what"], ["yes"], ["please"], ["thanks"], ["because"], ["easy"], ["good"], ["this"], ["that"], ["them"], ["ok"], ["you"], ["ll"], ["telegram"] ];
const secondReplacement = [ ["wat"], ["ye"], ["pls"], ["thx"], ["cuz"], ["ez"], ["gud"], ["dis"], ["dat"], ["dem"], ["okie"], ["u"], ["ll"], ["meowgram"] ];
const startReplacement = [ "uwaaa! ", "ugu, ", "rawr " ]
const endReplacement = [ [" OwO"], [" UwU"], [" :3"], [" xD"], [" <3"], [" o.o"], [" >w<"], [" wyaaaa"] ]

// fs.readFile( "./dataMain.xml", function(err, data) {
//   const xmlObj = xmlParser.toJson(data, {reversible: true, object: true})
//   console.log(xmlObj)
// })

fs.readFile( "./dataMain.xml", function(err, data) {
  const xmlObj = xmlParser.toJson(data, {reversible: true, object: true})
  const resources = xmlObj["resources"]["string"]

  for (let i = 0; i < resources.length; i++) {
    if (resources[i]) {
      // xmlObj["resources"]["string"][i].$t = xmlObj["resources"]["string"][i].$t.toLowerCase(); // trying to make it lower case

      if (xmlObj["resources"]["string"][i].$t == wordReplacement[i]) {
        // xmlObj["resources"]["string"][i].$t = xmlObj["resources"]["string"][i].replace(wordReplacement[i], secondReplacement[i]).$t; // trying to replace words
      }
    }

  }

  const stringifiedXmlObj = JSON.stringify(xmlObj)
  const finalXml = xmlParser.toXml(stringifiedXmlObj)

  fs.writeFile("./dataMain.xml", formatXml(finalXml, {collapseContent: true}), function(err, result) {
    if (err) {
      console.log("houston, we got a problem")
    } else {
      console.log("we did it, somehow")
    }
  })
})