Why js arrays, if there are objects?

In js objects are actually associative arrays, type the key value. So why not throw regular arrays ['foo', 'bar'], and to use for this object {'foo', 'bar'} (similar to {'1': 'foo', '2': 'bar'})?
July 8th 19 at 16:28
5 answers
July 8th 19 at 16:30
The arrays are the same objects, but with their methods and chips (the kids uncle Array), type, length, sort, join, splice, slice , etc.

They have a clear order, since the keys presented in the form of consecutive numbers. And this is the main reason why they are used - they can do everything to shred, sort, add new values at certain points.

In fact ["A", "B", "C"] as you can imagine new Array("A", "B", "C") and hence as {0 : "A", 1 : "B", 2 : "C"}.
July 8th 19 at 16:32
The guy you just (a bunch of mats).
Well, do you want a feature with these brackets so why not sing yourself broadcast your YAP
well, you do not think about the beauty of the language, and not to go. Eat what you give, and you will be happy. - Peyton44 commented on July 8th 19 at 16:35
July 8th 19 at 16:34
Who needs the array uses an array who dictionary dictionary.
the array is also a dictionary, with only numerical indices - Peyton44 commented on July 8th 19 at 16:37
: There is the question of performance and convenience. Like, and arranges the dictionary - use the dictionary. - Peyton44 commented on July 8th 19 at 16:40
July 8th 19 at 16:36
1) the object does not have .length
2) when a value is removed "from the middle" will have to do a rebuild indexes
3) ... I think I will add more compelling arguments ...
1) What prevents you to add the object the length property? :)
2) Well, in the arrays they are rebuilt, what is the problem here? - Peyton44 commented on July 8th 19 at 16:39
: well, why something to do, to add, if you already have a ready, convenient arrays? - Peyton44 commented on July 8th 19 at 16:42
: then that is superfluous entity. And what an array of the object? - mercedes commented on July 8th 19 at 16:45
: extra essence of ahahahhahahahaha, hahahahahahahaha, ha ha! - Peyton44 commented on July 8th 19 at 16:48
: you'd better sensible argument written) - Durward_Osinski commented on July 8th 19 at 16:51
: it's like another sivatel of the skin. - Peyton44 commented on July 8th 19 at 16:54
So you can decide what and integers are not needed, and real at the same time - because there is a line. - danny43 commented on July 8th 19 at 16:57
: I didn't say that arrays are not needed. I propose to use the shortcut {1,2,3} instead of [1,2,3], and as a bonus, the object will be able to quickly find out the number of elements. - Peyton44 commented on July 8th 19 at 17:00
: I'm not broken, and offer. And I expect you the adequate arguments. In a dispute born truth. - kavon.Murphy commented on July 8th 19 at 17:03
: Maybe in the future I will, who knows.
In General nothing prevents in the future to merge arrays and hashes, not even losing speed, just have to control the form in which the variable is used. As soon as appears a non-numeric index - immediately start working with it as a hash. - Daphne_Roob commented on July 8th 19 at 17:06
: > and as a bonus, the object will be able to quickly find out the number of elements.
speaking of birds: the lenght of the array and the number of elements in the array is not the same thing. - Peyton44 commented on July 8th 19 at 17:09
what is your returns length? - Peyton44 commented on July 8th 19 at 17:12
: length equal to the maximum index plus 1, not the actual count of elements.
and it's not in my opinion, and according to the specs.
just for fun - https://jsfiddle.net/1buLtq5o/ - Daphne_Roob commented on July 8th 19 at 17:15
well, apparently also a mistake of language, since the logic length (length) should return a length that is structure. - kavon.Murphy commented on July 8th 19 at 17:18
Then you can start a new dispute is whether the undefined element :)
The same thing will happen with delete(a[...]) - the element is there, but undefined. - Peyton44 commented on July 8th 19 at 17:21
: you see. and you're fucking with brackets when there are more other problems) - kavon.Murphy commented on July 8th 19 at 17:24
: I agree, also nonsense. The idea is if the element is empty, it must be null, if the element do not, undefined or error. - Peyton44 commented on July 8th 19 at 17:27
: Yes, no, not a bug. The array starts with zero, the element default is undefined. The creation of the element with number n implies that there are elements from 0 to n-1 - https://jsfiddle.net/1buLtq5o/1/ (long array) - Daphne_Roob commented on July 8th 19 at 17:30
July 8th 19 at 16:38
Don't like arrays - don't use them, nobody forces you.
I you want to simplify life, and you are so rude) - Peyton44 commented on July 8th 19 at 16:41
: Why would my life be easier? I'm a programmer. - Peyton44 commented on July 8th 19 at 16:44
: Well then, let's create a dozen language constructs: with lower case indices, uppercase, special signs.. - mercedes commented on July 8th 19 at 16:47
: I don't mind. - Peyton44 commented on July 8th 19 at 16:50
: well, actually - the thought of crazy: "the life of us easier"
I understand that you want to offer something intelligent to write his piece in history while doing nothing. But not in such a crazy way - Durward_Osinski commented on July 8th 19 at 16:53

Find more questions by tags JavaScript