私は、他の複数のオブジェクトを含むオブジェクトを渡すjavascript関数を持っています。javascriptでオブジェクト内のすべてのオブジェクトを反復処理する方法
createButtons({
normalButtons: {
button: {
type: 'website',
name: 'Website',
}
}
socialButtons: {
socialButton: {
type: 'fb-share',
name: 'Share on Facebook'
},
socialButton: {
type: 'copyUrl',
name: 'Copy Link'
}
}
});
今、私はすべてのsocialButtonsを反復処理したいが、私が使用しないときのために...ループの中で、それが唯一の最初の項目
function createButtons(options) {
for (x in options.socialButtons) {
console.log(options.socialButtons[x]);
}
}
を得るように見えることが唯一の1つのオブジェクトをログに記録します、Facebookのもの。
私は何か間違っているか、これを解決する良い方法がありますか教えてください。
ありがとうございました!
重複するキーがあります。 'socialButton'が2回発生する – thefourtheye