Created
March 24, 2025 06:55
-
-
Save nurrachmat-nr/e0aebce05296debcc0e45b9bd9ca950d to your computer and use it in GitHub Desktop.
Materi JavaScript Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <body> | |
| <h1>JavaScript Objects</h1> | |
| <h2>Creating an Object</h2> | |
| <p id="demo"></p> | |
| <p id="demo2"></p> | |
| <p id="demo3"></p> | |
| <script> | |
| // Create an Object: | |
| const car = {type:"Fiat", model:"500", color:"white"}; | |
| // Display Data from the Object: | |
| document.getElementById("demo").innerHTML = | |
| "The car type is " + car.type; | |
| //Object Mahasiswa | |
| const mhs = {npm: "2025210001", nama: "Nur Rachmat", prodi: "Informatika"}; | |
| var a = "Hallo"; | |
| let b = "Javascript"; | |
| document.getElementById("demo2").innerHTML = "Nama : <b>" +mhs.nama + "</b>"; | |
| //List of Object | |
| const listmhs = [ | |
| {npm: "2025210001", nama: "Nur Rachmat", prodi: "Informatika"}, | |
| {npm: "2025210002", nama: "Jenni", prodi: "Informatika"}, | |
| {npm: "2025210003", nama: "Jhonny", prodi: "Informatika"}, | |
| ]; | |
| var tampilnama = ""; | |
| //for (i = 0 ; i < listmhs.length ; i++){ | |
| listmhs.forEach((val, key) => { | |
| //console.log(listmhs[i].nama); | |
| console.log(val.nama); | |
| tampilnama += (key+1) + " Nama : <b>" +val.nama + "</b><br/>"; | |
| }); | |
| document.getElementById("demo3").innerHTML = tampilnama; | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment