We have a html div (first image) and array of strings (see second image)

We have to assign the single index like safety[A4] and safety[A5] to the text of div.
But currently it assign two footnote to same text like safety[A5][A4] since safety occurs two times in the html div.
Our current attempt is:
for (var i = 0 ; i < totalNumberOfItemsInCorrelationGrid; i++) {
var currentDataItem = data[i];
arr = new Array(currentDataItem.correlation_text, currentDataItem.corr);
arrOfCorrelatedTextOfCorrelationGrid.push(arr);
}
// sorting from bigger length of string to smaller length of string
arrOfCorrelatedTextOfCorrelationGrid.sort(function (a, b) {
return b[0].length - a[0].length; // ASC -> a - b; DESC -> b - a
});
arrOfCorrelatedTextOfCorrelationGrid.forEach(function (item) {
// item[0] gives value of corelated Text
// item[1] gives value of corr i.e A1 , A2 etc.
var _k = item[0].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$&");
_k = _k.replace(/^(\w)/, "\\b$1"); //This will add the word boundary at start of word only when it's useful.
_k = _k.replace(/(\w)$/, "$1\\b"); //This will add the word boundary at end of word only when it's usefull.
var _corelatedTextwithRegExpression = new RegExp(_k, 'g');
alert(_corelatedTextwithRegExpression);
_ObservationText = _ObservationText.replace(
_corelatedTextwithRegExpression,
"<span class='selectedTextAuto'>$&[" + item[1] + "]</span>"
);
});
How can this be done?