sneezry
V2EX  ›  问与答

JS 如何优雅地取出一个数组中后 N 个元素组成新的数组

  •  
  •   sneezry · Jan 27, 2015 · 11288 views
    This topic created in 4122 days ago, the information mentioned may be changed or developed.
    有一个数组,里面包含300个元素,现要取出后面的100个画出折线图,如何将这个数组优雅地截断?


    //Update
    array.slice(-100),好像是这个
    5 replies    2016-04-27 22:01:01 +08:00
    feiyuanqiu
        1
    feiyuanqiu  
       Jan 27, 2015
    var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    a.splice(-5, 5)
    zythum
        2
    zythum  
       Jan 27, 2015
    array.slice(array.length-100)
    kmvan
        3
    kmvan  
       Jan 27, 2015
    @zythum 朱一为啥渣浪的 https 经常被 firefox 警告说不被信任的https呢?
    zythum
        4
    zythum  
       Jan 27, 2015
    可能是https证书过期了。具体我也不是很清楚
    newbie269
        5
    newbie269  
       Apr 27, 2016
    刷一波~~~~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   995 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 19:48 · PVG 03:48 · LAX 12:48 · JFK 15:48
    ♥ Do have faith in what you're doing.