I have a javascript function that passes an object that contains multiple other objects, e.g.
createButtons({
normalButtons: {
button: {
type: 'website',
name: 'Website',
}
}
socialButtons: {
socialButton: {
type: 'fb-share',
name: 'Share on Facebook'
},
socialButton: {
type: 'copyUrl',
name: 'Copy Link'
}
}
});
Now i want to iterate through all the socialButtons, but when I do using a for ... in loop, it only seems to get the first item
function createButtons(options) {
for (x in options.socialButtons) {
console.log(options.socialButtons[x]);
}
}
It only logs 1 object, the Facebook one.
Am I doing something wrong or is there a better way to solve this, please let me know.
Thank you!
socialButtonoccurs two times