<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>类数组</title> </head> <body> <!-- Array.from --> <script> var obj={ 0:1, 1:2, 2:3, length:2 } // length 决定Array.from长度 obj-伪类 -类似于属猪的一种伪类 var newArr=Array.from(obj) console.log(newArr) console.log(newArr.length) </script> </body> </html>
// length 决定Array.from长度 obj-伪类 -类似于属猪的一种伪类
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>类数组</title> </head> <body> <!-- Array.from --> <script> var obj={ 0:1, 1:2, 2:3, push:[].push } // length 决定Array.from长度 obj-伪类 -类似于属猪的一种伪类 obj.push(4) console.log(obj) //{0:4,1:2,2:3,push:[].push} </script> </body> </html>