If one were to look at Java class Vector in the official API, there are certain conveniences such as creating a Vector object without specifying its initial length.
One can just add elements to it without having to specify the index (like an array).
One can also use .contains to determine if the Vector collection contains the element, without having to loop.
Is there such a type in Javascript?
JavaScript arrays don't have fixed lengths and are essentially equivalent to Vector.
.length
property keeps track of the biggest numerically-indexed property..indexOf
method is like .contains()
. (Don't make heavy use of this, either in Java or JavaScript. Version 6 of Ant, for example, had horrible performance problems in large projects because code was written to more-or-less use ArrayList instances like Maps. If you have collections of any size and need to do look-ups frequently, use a better data structure.)To add an element to the end, you can do either:
someArray.push( newValue );
or:
someArray[someArray.length] = newValue;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments