Intermediate Level - Sana-Mohammad-Rafiq25/js-Array-Object-task GitHub Wiki
Students' Names and Hobbies Data
Given an array of students:
let students = [
{
name: "Amna",
hobbies: ["eating", "cooking"]
},
{
name: "Daniyal",
hobbies: ["arts", "shopping"]
},
{
name: "Fahad",
hobbies: ["coding", "cooking"]
},
{
name: "Hajra",
hobbies: ["sleep", "reading"]
}
];
Q1. Print the following to the console:
solution:-
for (i = 0; i < students.length; i++) {
console.log('Hobbies of ' + ' ' + students[i].name)
console.log('1.' + students[i].hobbies[0])
console.log('2.' + students[i].hobbies[1])
}
Output:-
Hobbies of Amna 1. eating 2. cooking Hobbies of Daniyal 1. arts 2. shopping Hobbies of Fahad 1. coding 2. cooking Hobbies of Hajra 1. sleep 2. reading