我遇到一个问题,我想显示从对象数组中获取的数据..我的程序在控制台中显示我需要显示的数据..但是,每当我想在DOM中显示数据时/ body,它不能正确显示我的数据,仅显示对象的一个键值..我如何显示对象数组的所有键值???
请帮助我.........
let user1 = [{
name: "sagar",
pass: "1234",
}];
let feed = [{
name: "friend_1",
status: "New Friend",
}, {
name: "friend_2",
stats: "old friend",
}];
let intro = document.getElementById("intro");
let welcomeMsg = document.getElementById("welcomeMsg");
var username = document.getElementById("user");
var password = document.getElementById("pass");
let form = document.querySelector("form");
form.addEventListener("submit", (event) => {
event.preventDefault();
validation();
});
function validation() {
if (username.value == user1[0].name && password.value == user1[0].pass) {
for (let value of feed) {
console.log(value);
for (let key in value) {
setTimeout(() => {
welcomeMsg.innerHTML = `${key} of the person is : ${value[key]}`;
}, 300);
} // for loop end
}; // for off loop end
} else if (username.value == "" && password.value == "") {
welcomeMsg.innerHTML = `Username and Password Cannot be Blank`;
} else {
alert("Try again");
};
};