I have a collection of items, each item containing various attributes including a list of related elements:
{ name : 'Club 01'
, id : 1
, form : 45
, points : 0
, tactics : 'neutral'
, played : 0
, gameset : 0
, playedWith : [ 8, 1, 2, 3 ]
}
My goal is to iterate through the list and output all elements within the playedWith property:
for (let a = 0; a<clubs.length; a++) {
for (let b = 0; b<clubs[a].playedWith.length; b++) {
console.log(clubs[a].playedWith[b]);
}
}
This code works as expected for a single item, but when used within a loop as shown above, it returns:
undefined
What could be the issue with my code? How can I successfully log all items within the playedWith property?