JavaScript 數組對象切片


有的時候,前端向后端發送請求,json體積太大可以用數據切片分批發送請求

// 原數組
      const todolists = this.todolist.tableList
      // 切片的待保存數組
      const newArr = []
      // 切片數量
      const section = 15
      // 進行切片
      for (var i = 0; i < todolists.length; i += section) {
        newArr.push(todolists.slice(i, i + section))
      }
      // 循環切片次數
      for (let j = 0; j < newArr.length; j++) {
        console.log(newArr[j])
        // 發送請求記得使用await 同步提交請求
      }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM