Linked Questions
14 questions linked to/from Array() vs new Array()
4
votes
0
answers
98
views
Difference between "new Array()" and "Array()"? [duplicate]
Array function could called as a function like Array() or as constructor new Array(). Is there any difference between these 2 calling method?
1
vote
0
answers
78
views
new Array() vs Array() JavaScript [duplicate]
Usage of the var myArray = Array(10).fill(0); and var myArray = new Array(10).fill(0); seemingly return the same result.
Are there any differences between these two expressions? When should you use ...
-3
votes
2
answers
83
views
Why array created by Array(3) don't have index 0, 1, 2?
Array(3), result:
{ length: 3__proto__: Array(0) }
There is no index 0, 1, 2...
But Array.call(null, Array(3)) has,
{ 0: undefined, 1: undefined, 2: undefined, length: 3, __proto__: Array(0) }
I ...
-1
votes
1
answer
67
views
Difference between new Array() and Array() initialization syntax in JavaScript [duplicate]
Why are these two statements the same in JavaScript?
var a = new Array(5);
var a = Array(5);
Or, if they are not the same, what is different about them? Basically if I assign a to a different ...
1412
votes
56
answers
2.9m
views
How can I create a two dimensional array in JavaScript?
I have been reading online and some places say it isn't possible, some say it is and then give an example and others refute the example, etc.
How do I declare a 2 dimensional array in JavaScript? (...
886
votes
46
answers
691k
views
Most efficient way to create a zero filled JavaScript array?
What is the most efficient way to create an arbitrary length zero filled array in JavaScript?
dil's user avatar
- 9,062
970
votes
20
answers
940k
views
What’s the difference between "Array()" and "[]" while declaring a JavaScript array?
What's the real difference between declaring an array like this:
var myArray = new Array();
and
var myArray = [];
597
votes
13
answers
123k
views
Is JavaScript's "new" keyword considered harmful?
In another question, a user pointed out that the new keyword was dangerous to use and proposed a solution to object creation that did not use new. I didn't believe that was true, mostly because I've ...
212
votes
6
answers
421k
views
Declare an array in TypeScript
I'm having trouble either declaring or using a boolean array in Typescript, not sure which is wrong. I get an undefined error. Am I supposed to use JavaScript syntax or declare a new Array object?
...
user avatar
user3325783
19
votes
6
answers
25k
views
How to 'repeat' an array n times [duplicate]
In python you can do:
arr = [1,2,3] * 3
print(arr)
output:
[1,2,3,1,2,3,1,2,3]
Is there a concise way of doing this in java script? The best I can think of is something like:
let arr2 = [...arr, ......
1
vote
0
answers
252
views
Initialize an array without `new` keyword in javascript [duplicate]
What is the difference between these two way of initializing an array in modern javascript environment (in ES6 spec) ?
const arr1 = new Array(3);
const arr2 = Array(3);
They look same running in ...
1
vote
3
answers
122
views
What the different between `new Array(n)` and `Array(n)`
What the different if both of them call the constructor "Array" and generate an object?
I know that we lost this if we create some object without new:
function Animal(name) {this.name = name}
var ...
1
vote
1
answer
78
views
Matrix Preallocation in Javascript
I've been playing around with generating image filters using canvas, and I was attempting to improve speed by preallocating an entire matrix from the beginning.
This code was the first thing that I ...
0
votes
2
answers
82
views
Comparison of the two situations when the constructor is called without the new keyword
function Person(name, age, gender) {
this.name = name; // run
}
function PersonSafe(name) {
if (!(this instanceof arguments.callee))
return new PersonSafe(name)
this.name = name; //...