GamerPro
GamerPro
KPCKevin Powell - Community
Created by GamerPro on 10/25/2023 in #front-end
Problem with reading information from array
Hello there, I have the following problem: This is my JS Code:
var locales = {};

window.addEventListener("message", function(event) {
let data = event.data;
switch (data.type) {
case "open":
locales = {
Servername: data.locales[0],
GarageTitle: data.locales[1],
ImpoundTitle: data.locales[2],
ParkedIn: data.locales[3],
ParkedOut: data.locales[4],
Impounded: data.locales[5],
ParkIn: data.locales[6],
ParkOut: data.locales[7],
ParkOutImpound: data.locales[8],
SearchCarHeading: data.locales[9],
SearchCarDescription: data.locales[10],
SearchPlaceholder: data.locales[11]
};

$(".server-name").text(locales.Servername);

break;
}
});
var locales = {};

window.addEventListener("message", function(event) {
let data = event.data;
switch (data.type) {
case "open":
locales = {
Servername: data.locales[0],
GarageTitle: data.locales[1],
ImpoundTitle: data.locales[2],
ParkedIn: data.locales[3],
ParkedOut: data.locales[4],
Impounded: data.locales[5],
ParkIn: data.locales[6],
ParkOut: data.locales[7],
ParkOutImpound: data.locales[8],
SearchCarHeading: data.locales[9],
SearchCarDescription: data.locales[10],
SearchPlaceholder: data.locales[11]
};

$(".server-name").text(locales.Servername);

break;
}
});
I can perfectly read the information out of the locales array when inside the event listener but when I try to console.log something from the array somewhere else in my code it suddenly does not work anymore. Can anyone help me with that? Greetings, and thanks in advance. 🙂
23 replies