• <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>

    怎么把遍歷出來的字符串push到一個數組

    數組遍歷對象添加到某個數組

    方式/步調

    1. 1

      一、輪回json數組,提取此中某個對象添加到數組中

    2. 2

      var that.lists = [某個json];

      for(let i =0;i < that.lists.length; i++){

      var str={};

      str.id = that.lists[i].id;

      str.storeNo = that.lists[i].store_no;

      str.cityProductId = that.lists[i].city_product_id;

      that.requisit.push(str)

      }

    3. 3

      二、for in 輪回,數組添加

    4. 4

      var data=[];

      var foo = {"name":"john","sex":"meal","height":"168","weight":"52"};

      for(var i in foo) {

      data.push(foo[i])

      console.log(foo[i]); // 輸出 john、meal、168、52

      }

      console.log(data); // 輸出  ["john", "meal", "168", "52"]

    5. 5

      拓展:

      數組元素的添加:

      var arrayObj = [];

      arrayObj. push();// 將一個或多個新元素添加到數組結從頭至尾,并返回數組新長度

      arrayObj.unshift();// 將一個或多個新元素添加到數組起頭,數組中的元素主動后移,返回數組新長度

      arrayObj.splice();//將一個或多個新元素插入到數組的指定位置,插入位置的元素主動后移,返回""。

    6. 6

      數組元素的字符串化,join()

      var arr = ['A', 'B', 'C', 1, 2, 3];

      arr.join('-'); // 'A-B-C-1-2-3'

    7. 7

      數組的截取和歸并

      var arrayj = [];

      array.slice(start, [end]);

      //以數組的形式返回數組的一部門,注重不包羅 end 對應的元素,若是省略 end 將復制 start 之后的所有元素


      array.concat();

      //將多個數組(也可所以字符串,或者是數組和字符串的夾雜)毗連為一個數組,返回毗連好的新的數組

      示例:

      let goodsData = [];

      let num = 0;

      let amount = 0;

      basicGoods.forEach(item => {

      num += Number(item.num);

      amount += Number(item.amount);

      });

      goodsData = basicGoods.concat({

      id: '總計',

      num,

      amount,

      });


    • 發表于 2019-06-06 00:20
    • 閱讀 ( 1058 )
    • 分類:其他類型

    你可能感興趣的文章

    相關問題

    0 條評論

    請先 登錄 后評論
    admin
    admin

    0 篇文章

    作家榜 ?

    1. xiaonan123 189 文章
    2. 湯依妹兒 97 文章
    3. luogf229 46 文章
    4. jy02406749 45 文章
    5. 小凡 34 文章
    6. Daisy萌 32 文章
    7. 我的QQ3117863681 24 文章
    8. 華志健 23 文章

    聯系我們:uytrv@hotmail.com 問答工具
  • <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>
    久久久久精品国产麻豆