简体   繁体   English

如何使用Alert在弹出框JavaScript中显示数组?

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

I am pretty new to Javascript 我是Java的新手

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. 到目前为止,我已经有了这个,但是我很困惑如何在jsfiddle中使用纯JavaScript在弹出框中显示数组。

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. 您可以将任何jquery插件用于显示弹出框。

<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); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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