如何在没有for循环的情况下用JavaScript显示数组

How to display array in JavaScript without for loop?

本文关键字:情况下 JavaScript 显示 数组 循环 for      更新时间:2023-09-26

我正在尝试查询我在Parse.com上使用的信息。我有一个信息数组,我想使用它们containedIn方法从中查询。

以下是Parse中的一个示例,说明如何使用包含在方法中的:

// Finds scores from any of Jonathan, Dario, or Shawn
query.containedIn("playerName", ["Jonathan Walsh", "Dario Wunsch", "Shawn Simon"]);

以下是我尝试的方式:

var holdingTheDaysInCurrentMonth = []; //declare array
//for loop to put info inside of it
for(var i = startDateDay; i <=endDateDay; i++) {
    var dayInMonth = i.toString();
    holdingTheDaysInCurrentMonth.push(dayInMonth);  
}
//... code to query Parse
//how I am calling my method
alert(holdingTheDaysInCurrentMonth.toString());
query.containedIn("dayString", [holdingTheDaysInCurrentMonth.toString()]);

在我的警报中,当我点击本月1日和6日时,我会收到1、2、3、4、5、6的回复(这是意料之中的事)。我的查询没有返回任何检索到的行,所以一定是查询错误了。如何更改格式以正确使用?我做错了什么?

您需要执行以下操作:

query.containedIn("dayString", holdingTheDaysInCurrentMonth);

第二个参数可以是实际的数组,因此不需要将其转换为字符串。

相关文章: