I have an object that looks like this:
var set_1 = {
id: 'set_1',
nameofSet : 'English fruits',
category: 'languages',
cards : [
{
front : 'apple',
back : 'jablko'
},
{
front : 'orange',
back : 'pomarancza'
},
{
front : 'pear',
back : 'gruszka'
}
]
}
Now there's a function:
$('#chooseSet').on('click', '.setName', function() {
var setName = this.getAttribute("data-set-name");
editCards(setName);
});
This is the HTML:
<div class="setName" data-set-name="set_1">English fruits</div>
It gives the setName parameter to the editCards function that looks like this:
editCards(setName) {
console.log(setName); // logs "set_1"
console.log(setName.cards); // logs "undefined" - why?
console.log(set_1.cards); // logs the `cards` array from `set_1'.
// code
}
It takes the setName parameter.
My question is - why doesn't the second console.log give me the cards' array as it does in the thirdconsole.log` example?
console.log(window[setName].cards)