小编Kir*_*ill的帖子

在node.js中是否需要json

我想在我的JavaScript代码中包含几个JSON文件,这些文件与我的JavaScript源文件位于同一目录中.

如果我想要包含另一个JavaScript文件,我可以简单地使用require.现在我正在使用readFileSync__dirname获得JSON,我认为这是一种丑陋的方式.

是否有类似的要求,使我能够加载JSON文件?

json require node.js

219
推荐指数
7
解决办法
18万
查看次数

按索引和匹配值过滤数组

我想过滤掉老虎机的模式,在这种情况下,如果它们具有相同的值,我希望选择以下索引.

如果应该输出索引0,2和6具有相同的值.我在想像函数调用这样的东西

if (win_filter([0, 2, 6] == "slot-2") {
    console.log("You won");
}
Run Code Online (Sandbox Code Playgroud)

我的代码如下.

var final_score = new Array();

$(".shoot").click(function() {

  //var numbers_array = ["slot-1", "slot-1", "slot-1", "slot-1", "slot-1", "slot-2", "slot-2", "slot-2", "slot-2", "slot-3", "slot-3", "slot-3", "slot-4", "slot-4", "slot-5"];
  var numbers_array = ["slot-1", "slot-2", "slot-3", "slot-4", "slot-5"];
  var target = $("div.window table");

  target.find("tr td > div").each(function() {
    $(this).fadeOut(function() {
      $(this).removeAttr('class');
      $(this).addClass(numbers_array[Math.floor(Math.random() * numbers_array.length)]);
      $(this).fadeIn();
      final_score.push($(this).attr("class"));
    });
  });

  function filterResults(arr) {
    return final_score.filter(function(el) {
      return arr.some(function(e) {
        return el.timeframe == e;
      }); …
Run Code Online (Sandbox Code Playgroud)

javascript arrays jquery

13
推荐指数
1
解决办法
616
查看次数

标签 统计

arrays ×1

javascript ×1

jquery ×1

json ×1

node.js ×1

require ×1