Array.from()方法數組
1 var obj = { 2 0: 'a', 3 1: 'b', 4 2: 'c', 5 length: 3 6 } 7 var arr = Array.from(obj,function(item,index){ 8 return item + index 9 })
Array.from()做用和map方法有些相似,能夠將類數組轉換爲數組
輸出結果:spa
假如咱們有一個這樣的需求code
1 <div>1</div> 2 <div>2</div> 3 <div>3</div> 4 <div>4</div> 5 <div>5</div> 6 7 咱們要獲取多個div裏的值,經過Array.from()就能夠獲取到innerHTML 8 9 var divs = document.getElementsByTagName('div') 10 var divTexts = Array.from(divs,function(item,index){ 11 return item.innerHTML 12 })
輸出結果blog
---------------------------------------------------------------------------------------------------------------------------------長長的分割線get
Array.of()it
Array.of是將一組數轉換爲數組io
1 var arr = Array.of(6) 2 function arrayOf(){ 3 return 4 }
輸出結果function