# toArray

目錄:數組

  1. Array.prototype.slice.call
  2. Array.from
  3. Array.of
  4. const toArr = (...args) => args

Array.prototype.slice.call

類數組對象(Array-like)this

/** argument 類數組對象 */
Array.prototype.slice.call(arguments)

/** 簡寫 */
[].slice.call(arguments)

Array.from

參數:類數組對象、可迭代的對象prototype

Array.from(arrayLike[,mapFn[,thisArg]])
// 用法
Array.from(arguments)

Array.of

Array(7) // 建立一個長度爲7的空(empty)數組 [,,,,,,]
Array.of(7) // [7]

toArr

剩餘參數語法code

const toArr = (...args) =>  args
toArr(1,2,3,4) // [1,2,3,4]
相關文章
相關標籤/搜索