javascript - 相互检查数组变量

标签 javascript arrays

var carpets = [];
$.get("pullCarpets.php", function($carpets){
    $.each($carpets, function(i, item){
        console.log(item.id);
        for(var j = 0; j < carpetArray.length; j++){
            console.log(carpetArray[j];
            if(carpetArray[j] == item.id){
                list.push(item);
            }
        }
    });
}, "json");
console.log(carpets);

基本上我认为一切都在按其应有的方式进行。但是从 php 文件($carpets)中提取的地毯数组和对象数组都相当长,其中有一百个左右的变量。当我尝试运行代码时,我在控制台中收到一条错误消息,指出 javascript 控制台中出现错误,功能可能会受到影响。我猜控制台不喜欢向我显示所有数字,但由于某种原因,当我运行该函数时什么也没有发生。

脚本中的这一点后面是另一个 $.each 迭代器,它将地毯的内容显示到 div 中,但它不起作用。

如有任何帮助,我们将不胜感激,谢谢。

最佳答案

似乎您在第 6 行缺少 ),并且 carpetArraylist 不存在

var carpets = [];
var list = [];

$.get("pullCarpets.php", function($carpets){
    $.each($carpets, function(i, item){
        console.log(item.id);
        for(var j = 0; j < carpets.length; j++){
            console.log(carpets[j]);
            if(carpets[j] == item.id){
                list.push(item);
            }
        }
    });
}, "json");
console.log(carpets);

关于javascript - 相互检查数组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30004521/

相关文章:

arrays - Matlab结构体中的Push_back元素

Javascript无限类别深度树

javascript - 如何将javascript中的数字数组转换为字符串?

javascript - 无法通过 ajax 发送文件 ( print_r($_FILES); Array ( ) )

javascript - 点击似乎被模糊阻挡

c++ - 写在文件上,信息最终出现在控制台中

arrays - 字典的每个值组合

jQuery 多维数组删除重复项

c# - 检查页面上是否已加载 javascript 文件

javascript - 为什么我们不应该使用 ref?