javascript foreach in object
const students = {
adam: {age: 20},
kevin: {age: 22},
};
Object.entries(students).forEach(student => {
// key: student[0]
// value: student[1]
console.log(`Student: ${student[0]} is ${student[1].age} years old`);
});
/* Output:
Student: adam is 20 years old
Student: kevin is 22 years old
*/Object.keys(obj).forEach(function (key) {
// do something with obj[key]
});for (var key in validation_messages) {
// skip loop if the property is from prototype
if (!validation_messages.hasOwnProperty(key)) continue;
var obj = validation_messages[key];
for (var prop in obj) {
// skip loop if the property is from prototype
if (!obj.hasOwnProperty(prop)) continue;
// your code
alert(prop + " = " + obj[prop]);
}
}
Also in JavaScript:
- redirect to page in javascript
- js standard global
- javascript open new window
- Javascript string compression
- bootstrap 4 form validator with jquery
- javascript operator double not
- how to set up a success message show up if form is submitted in react hooks
- set navigation drawer to open by default react native
- how to debug node js file in webpack
- javascript console input
- angular input press enter
- mobile number format (xxx) xxx-xxxx
- js for
- access selected option in jquery
- how to write a json in r
- for in javascript
- get execution time in javascript
- javascript date
- promise nodejs
- javascript to help find overflow elements
- react Refused to execute inline script because it violates the following Content Security Policy directive
- javascript if array key exists
- server info discord.js
- node js code for saving first middle and last name