數組大概知多少

博客文章連接:數組大概知多少javascript

判斷一個變量是否爲數組?

可靠地檢測數組方法java

1.利用ObjecttoString方法git

var list = [1, 2, 3];
Object.prototype.toString.call(list);//[object Array]

2.利用ES5Array.isArray()方法github

var list = [1, 2, 3];
Array.isArray(list);//true
數組的原生方法有哪些?

會改變自身的方法:數組

  • copyWithinfillpoppushreverseshiftsortspliceunshift

不會改變自身的方法:prototype

  • concatincludesjoinslicetoSourcetoStringindexOflastIndexOf

遍歷方法:code

  • forEachentrieseverysomefilterfindfindIndex
  • keysmapreducereduceRightvalues

如何將類數組的變量轉化爲數組?ip

  • 若是是ES6,能夠用Array.from()方法。
  • 一般用Array.prototype.slice.call()的方法,將相似數組轉換爲數組。
相關文章
相關標籤/搜索