Sorry for the basic question - this is a simplified version of much larger code which I cannot seem to solve this issue -
I have a JS created blog, im storing my blog details in a object and populating the HTML with those details, this lets me keep to DRY principle.
The issue I have found is that I cannot seem to use variables to complete a Objects path -
Create the Object >>
var objectExample = {
one: [{
method: function(x,y){
console.log(`${x} ${y}`);
}
}]
}
var blockThing = document.querySelector('.block');
var name = 'one';
var sign = 0;
x = 'something new';
y = 'another new thing';
blockThing.addEventListener('click', function(){
objectExample.name[sign].method(x,y);
});
I'm not sure why the above does not work as if I were to write
blockThing.addEventListener('click', function(){
objectExample.one[0].method(x,y);
});
i.e. not using variables - then it does work.
Please excuse me if this is a super basic question, I've been trying to resolve this is my larger example for an embarrassing amount of hours now.
Thank you for any help