Javascript 无法将普通数组转换为jquery数组

Javascript 无法将普通数组转换为jquery数组,javascript,jquery,arrays,Javascript,Jquery,Arrays,加载时,我必须禁用NEXT按钮,但为此,我必须将我的普通数组转换为jquery数组 我试过了,但它在控制台中显示出一些奇怪的价值。所以请帮我做这个 html 输出:(数组配方和lastRecipeId变量的大小输出错误) 为什么会有这种奇怪的输出。jQuery.makeArray()将类似数组的对象转换为数组 使用JSON.parse()将字符串转换为数组 尝试: 而不是 var recipArray = jQuery.makeArray(wholeRecipes); 您不是从数组开始,而

加载时,我必须禁用NEXT按钮,但为此,我必须将我的普通数组转换为jquery数组

我试过了,但它在控制台中显示出一些奇怪的价值。所以请帮我做这个

html

输出:(数组配方和lastRecipeId变量的大小输出错误)

为什么会有这种奇怪的输出。

jQuery.makeArray()
将类似数组的对象转换为数组

使用
JSON.parse()
字符串转换为数组

尝试:

而不是

var recipArray = jQuery.makeArray(wholeRecipes); 

您不是从数组开始,而是从一个字符串开始。
的内容仅读取为一个简单字符串。如果希望将其解释为数组,可以将其提供给JSON解析器:

    var wholeRecipes = JSON.parse($("#wholeRecipeIds").html());
实际上没有必要这样做:

    var recipArray = jQuery.makeArray(wholeRecipes); 

一旦解析了元素的原始内容,就有了一个JavaScript数组。实际上没有“jQuery数组”这样的东西,这不是API的用途。

makeArray将类似数组的对象转换为真正的JavaScript数组

    var nextRowIndex = '32661'
        wholeRecipes=$("#wholeRecipeIds").html(),
        recipArray = $.parseJSON(wholeRecipes), 
        lastRecipeId = recipArray[recipArray.length-1];

    console.log("New array recips:"+recipArray);   
    console.log("size of array recipe:"+recipArray.length);   
    console.log("lastRecipeId in array :"+lastRecipeId);  
    if(nextRowIndex==lastRecipeId){
       $("#next").attr('disabled','disabled');
   }

你能理解我的问题吗?如果不能,请回答我。我正在将整个数字字符串放入数组的第一个索引中。你需要将该数字字符串拆分成一个数组。makeArray expect object param,你给了他一个字符串…试试JSON。parse()这是
recipArray
现在:
[“\n[3618、5143、5144、5146、9728、16497、4002、4852、2864、32661]\n“]
将类似数组的对象转换为数组,而不是将字符串转换为类似
JSON.parse()
的数组。加载页面时,需要禁用“下一步”按钮
.makeArray()
API用于
参数
节点列表
实例;具有数字索引属性和
长度
属性的对象。
var recipArray = jQuery.makeArray(wholeRecipes); 
    var wholeRecipes = JSON.parse($("#wholeRecipeIds").html());
    var recipArray = jQuery.makeArray(wholeRecipes); 
    var nextRowIndex = '32661'
        wholeRecipes=$("#wholeRecipeIds").html(),
        recipArray = $.parseJSON(wholeRecipes), 
        lastRecipeId = recipArray[recipArray.length-1];

    console.log("New array recips:"+recipArray);   
    console.log("size of array recipe:"+recipArray.length);   
    console.log("lastRecipeId in array :"+lastRecipeId);  
    if(nextRowIndex==lastRecipeId){
       $("#next").attr('disabled','disabled');
   }