[Vuejs]-How to send 10 items from an array in each request until the array is empty

0πŸ‘

βœ…

I used lodash.chunk it does great job by splitting my cards array into small chunks each chunk is 10 cards , and when the last chunk is 4 cards or something lower than 10 it will count it as chunk also ,, worked for me β€” thanks to Long Nguyen for pointing me out to lodash

and here is the code :

 cardsRefactoring() {
      const cardsarry = this.cardsString.split("\n");
      if (this.cardsPostData.type == "Earthlink") {
        for (let i = 0; i < cardsarry.length; i++) {
          const card = cardsarry[i];
          const carditems = card.split(",");
          const obj = {
            serial: carditems[0],
            username: carditems[1],
            password: carditems[2]
          };
          this.allProcessedCards.push(obj);
        }
      } else {
        for (let i = 0; i < cardsarry.length; i++) {
          const card = cardsarry[i];
          const carditems = card.split(",");
          const obj = {
            serial: carditems[0]
          };
          this.allProcessedCards.push(obj);
        }
      }
      const chunkedCards = _.chunk(this.allProcessedCards, 10)
      for(let i=0 ;i < chunkedCards.length; i++){
        const chunk = chunkedCards[i];
         for(let i = 0; i< chunk.length; i++){
          this.cardsPostData.cards.push(chunk[i])
        } 
        console.log("chuncked ten", this.cardsPostData.cards);

        this.cardsPostData.cards = []
      } 
    },

Leave a comment