hw10_12_read array of objects.html 649 B

123456789101112131415161718192021222324
  1. <head>read array of objects</head>
  2. <body>
  3. <script>
  4. const readArrayOfObjects = () => {
  5. const arr = [];
  6. do {
  7. let obj = null;
  8. while ((key = prompt("Enter obj property name")) &&
  9. (val = prompt("Enter obj property value"))) {
  10. if (!obj)
  11. obj = {};
  12. obj[key] = val;
  13. }
  14. if (obj)
  15. arr.push(obj);
  16. }
  17. while (confirm("continue&&???..."))
  18. return arr;
  19. }
  20. console.log(readArrayOfObjects());
  21. </script>
  22. </body>