Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
if you can do something like new Array(20) to create an array with 20 undefined i would understand it since then arr.length is 20..
-
C0D4694766ynot JS, but I know a PHP dev who does this
And then every array key after it is
$arr = [];
$arr[“key1”] = 123;
$arr[“key2”] = 456;
And so on 🤦♂️🔫
Instead of
$arr = array(“key1” => 123, “key2” => 456); -
Froot75836y@romangraef True, but if you map over it and expect to get 20 results back you'll be disappointed 😄
So basically
(new Array(20)).fill(0).map(x => "woop woop")
is what you need if you want that sort of thing 😄 -
Kekica9586yMy preffered way is with [] but I dont really care if someone is using constructor. People are making more fked up things in js than this.
!rant
Does anyone know a JS dev who uses constructors for simple things like object and arrays, instead of literal.
Meaning:
var arr = [] ;
vs.
var arr = new Array() ;
And if you do this. Why? Just seems tougher to read to me. I saw a use for dynamically creating regex, and I get that. But any other legit reasons?
rant
literals vs constructors