前端数据处理,遍历数组,取出数组数据并传参

如何遍历数组collectlist,用data取出数据fid,然后再把data作为参数调用querydata函数,自己写的代码如下,一直没达到预期目的

img

created: function () {
    this.querybyfid(this.userId);
    for(let i=0;i<this.collectsum;i++){
      this.querydata(this.collectlist[i].fid);
    }
  }

i<this.collectsum.length


created: function () {
        this.querybyfid(this.userId);
        for(let i=0;i<this.collectlist.length;i++){
          this.querydata(this.collectlist[i].fid);
        }
      }
 

用这个替换你那个循环

this.collectlist.forEach(el=>{
  this.querydata(el.fid);
})

换个生命周期,在mounted里写

很抱歉,我不清楚您正在编写的代码是什么。如果您可以提供更多的上下文和细节,我将尽力帮助您解决问题。 一般来说,在前端处理数组时,您需要使用JavaScript的数组方法和函数来遍历和操作数组。以下是一个可能的解决方案: ```javascript const arr = [1, 2, 3, 4, 5]; function遍历数组(arr, fid) { for (let i = 0; i < arr.length; i++) { if (arr[i] === fid) { return arr[i]; } } return null; } const result =遍历数组(arr, '1'); console.log(result); // 输出 [1] ``` 在上面的示例中,我们首先定义了一个名为`arr`的数组,并定义了一个名为`遍历数组`的函数,该函数接受一个数组和一个fid参数,并使用for循环遍历数组,检查每个元素是否与fid相等。如果相等,则返回该元素。如果未找到相等的元素,则返回null。 接下来,我们将调用`遍历数组`函数,并将`arr`和`fid`参数传递给它。最后,我们将结果存储在`result`变量中,并使用console.log函数将其输出到控制台。 希望这可以帮助您解决问题!