我有一個像這樣的 JSON 對象:[{"user": "poetry2", "following": ["Moderator", "shopaholic3000"]}]我正在使用這樣的 Fetch API: fetch (`/profile/${username}/following`) .then(response => response.json()) .then(profiles => { profiles.forEach(function(profile){ profileDisplay = document.createElement('button'); profileDisplay.className = "list-group-item list-group-item-action"; profileDisplay.innerHTML = ` ${profile.following}`; listFollowing.appendChild(profileDisplay); }) })現在,它在同一個按鈕中顯示以下用戶,如下所示:<button class="list-group-item list-group-item-action"> Moderator,shopaholic3000</button>如何修改 Fetch 調用以在單獨的按鈕中顯示以下每個用戶。更像這樣的東西:<button class="list-group-item list-group-item-action"> Moderator</button><button class="list-group-item list-group-item-action"> shopaholic3000</button>
在 Fetch 調用中迭代數組
Qyouu
2023-07-06 10:14:17