-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.js
More file actions
39 lines (28 loc) · 1.21 KB
/
object.js
File metadata and controls
39 lines (28 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// ---------------------------------------------------------------------------------------------------------
// OBJECTS => Collection of named objects
// ---------------------------------------------------------------------------------------------------------
// syntax => {key: value pairs} enclosed in { }
const array1 = [ "Iman", "Mike", " Mbugua", "Shadrack"] // This is an array
// console.log(array1[2]); // accessing the array
const obj1 = {fname: "Iman", age : 22 , school: "MS"} // This is an object
// How to access items
console.log(obj1["school"]); // or
console.log(obj1.age);
console.log(Object.keys(obj1));
// console.log(Object.values(obj1));
// for (let i in obj1){
// // console.log(i + " "+ obj1[i]);// this will display the value items in the object
// }
const obj2 = [{fname: "Isaac", age : 21 , school: "MS"},
{fname: "Jeff", age : 23 , school: "MS"},
{fname: "Radde", age : 24 , school: "MS"}];
// console.log(Object.values(obj2[1]));
// console.log(obj2[2]);
for(x in obj2[2]){
console.log(obj2[2][x]);
}
// MAPS -
const a = obj2.map((obj2)=>{
return `${obj2.fname}`
})
console.log(a);