new Array() vs Object.create(Array.prototype)

前端 未结 2 1679
梦谈多话
梦谈多话 2020-12-17 23:23

A naive confusion:

var arr1 = new Array();
var arr2 = Object.create(Array.prototype);
//Inserting elements in \"both arrays\"
arr1[0] =0;
arr1[9] =9;
arr2[0]         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 23:54

    var arr1 = new Array(); is the proper way to instantiate an array. It is the same as using the array literal: var arr1 = [];

提交回复
热议问题