简体   繁体   中英

How to use alert to display an array in a popup box javascript?

I am pretty new to Javascript

I have been assigned to make a database using objects and organizing them into an array. I need to make sure the user can see all the objects in the array, allow the user to add and remove any objects, and allow the user to search for any objects. So far I have this but I am stumped on how to display the array in a popup box using purely javascript in jsfiddle.

var books = [

 book1 = {
    bookName: "Keeper of the Lost Cities",
    author: "Shannon Messenger",
    goodreadsRating: "4.5/5"
  },

 book2 = {
    bookName: "Eragon",
    author: "Christopher Paolini",
    goodreadsRating: "3.9/5"
   },

  book3 = {
    bookName: "The House of the Scorpion",
    author: "Nancy Farmer",
    goodreadsRating: "4.1/5"
   }
];

let array = books;

You can use any jquery plugin for display popup box.

<script src="../popupJquery.js"></script>  
<div id="contentId" style="display:none">
<script>
   $(function(){
    $('#contentId').popModal({
     html : /*convert your javascript array in html like in table**/
     });
   });
</script>

Use the code below for reference.

See the result

  var books = [ book1 = { bookName: "Keeper of the Lost Cities", author: "Shannon Messenger", goodreadsRating: "4.5/5" }, book2 = { bookName: "Eragon", author: "Christopher Paolini", goodreadsRating: "3.9/5" }, book3 = { bookName: "The House of the Scorpion", author: "Nancy Farmer", goodreadsRating: "4.1/5" } ]; var str = ""; books.forEach(function(d){ str += JSON.stringify(d); }); alert(str); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM