<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
//javascript Array
const arr1 = new Array(10) //length为10的空数组
const arr2 = new Array(10, 20, 30) // [10,20,30]
console.log(arr1, arr2)
//静态方法
//Array.of
const arr3 = Array.of(10) //[10]
const arr4 = Array.of(10, 20, 30) //[10,20,30]
console.log(arr3, arr4)
//Array.isArray
console.log(Array.isArray([]), Array.isArray('[]')) //true false
//Array.from();
const arr5 = Array.from(
'hello',
function (item, index) {
console.log(item, index, this) //this={}
return item
},
{}
)
console.log(arr5) //["h","e","l","l","0"]
const arr6 = Array.fromAsync(
'hello',
function (item, index) {
console.log(item, index, this) //this={}
return item
},
{}
)
console.log(arr6) //Promise {<pending>}Array(5)
</script>
</body>
</html>
javascript Array (1)
最新推荐文章于 2024-09-04 20:18:34 发布