Home - Sana-Mohammad-Rafiq25/js-Array-Object-task GitHub Wiki
- Welcome to the js-Array-Object-task wiki!#
Access Methods
Q1. How will you access the third position of the following array?
let arr = [5, 10, 15]
Solution:-
console.log(arr[2]);
Q.2 How will you access the second element, degree from the following object?
let obj = { name: "Maimoona", degree: "MBBS" }
Solution:-
console.log(obj['degree'])
Q.3 How will you access all elements of the following array using loops?
let arr = [1, 2, 3, 4, 5, 6, 7]
Solution:-
for (i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
Q.4 How will you access all elements of the following object using loops?
let obj = { name: "Maimoona", degree: "MBBS", age: 25 }
Solution:-
for (let property in obj) {
console.log(`${property}: ${obj[property]}`);
}