JS Dasar: 40. For in

by istiq20

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>For in</title>
  </head>
  <body>
    <script>
      
      // for in di object
      const person = {
        firstName: "EKo",
        middleName: "Kurniawan",
        lastName: "Khannedy",
      };

      for (const property in person) {
        document.writeln(`<p>${property} : ${person[property]}</p>`);
      }

      // for in di array (tidak disarankan)
      const names = ["Eko", "Kurniawan", "Khannedy"];
      for (const index in names) {
        document.writeln(`<p>${index} : ${names[index]}</p>`);
      }

    </script>
  </body>
</html>