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

时间:2014-09-18 00:09:50

标签: javascript arrays parse-platform

我正在尝试查询我在Parse.com上使用过的信息。 我有一个信息数组,我想通过使用containsIn方法来查询。

以下是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的回复。我从查询中找不到检索到的行,因此必须查询错误。如何更改格式才能正确使用?我做错了什么?

1 个答案:

答案 0 :(得分:1)

您需要执行以下操作:

query.containedIn("dayString", holdingTheDaysInCurrentMonth);

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