In this object, I want to print out an array in the form of [userName, skills]. I know that these objects don't have indexes. Is it possible to detect the skills
property and only print out the value of that?
const users = {
Alex: {
email: 'alex@alex.com',
skills: ['HTML', 'CSS', 'JavaScript'],
age: 20,
isLoggedIn: false,
points: 30
},
Asab: {
email: 'asab@asab.com',
skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'],
age: 25,
isLoggedIn: false,
points: 50
},
Brook: {
email: 'daniel@daniel.com',
skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'],
age: 30,
isLoggedIn: true,
points: 50
}
}
I first tried the code below but there was an error that it cannot read properties of undefined (reading 0).
let userId = Object.keys(users); //(3) ['Alex', 'Asab', 'Brook']
for (let i = 0; i < userId.length; i++) {
let userSkills = users.userId[i].skills;
console.log(userId, userSkills);
}
Is it the only way that I check all the skills one by one like below?
console.log(users.Alex.skills);
console.log(users.Asab.skills);
console.log(users.Brooks.skills);