Это мой первый вопрос на форуме. Я много искал, прежде чем спрашивать вас, ребята, но, возможно, из-за того, что я все еще развиваю свои навыки JavaScript, я не мог понять это.
Я пытаюсь передать объект в качестве аргумента динамически, в соответствии с URL, как показано ниже.
let createDataLayer = () => {
//Creating objects with the values for each page
someurl = {
pageType: 'Content',
institution: 'Institution',
contentTopic: 'Membership',
productCategory: '',
productName: '',
};
//Attaching the right array to the actual url
let actualURL = "/some-url/";
actualURL = actualURL.replace(/-/g,"");
actualURL = actualURL.replace(/\//g,"");
//Function that applies the right content to the right page
let applyingContent = (variable) => {
console.log("Always come as string: ", typeof variable); //string
console.log("Can't access the object: ", variable.pageType); //undefined
console.log("If I call the variable itself, it's here: ", someurl); //the object logs ok
window.dataLayerValues = [variable.pageType, variable.institution, variable.contentTopic, variable.productCategory, variable.productName];
return window.dataLayerValues;
}
applyingContent(actualURL);
}
createDataLayer();
Кто-нибудь может мне помочь, пожалуйста?
Я очень ценю это!