A History of the Javascript Array Object
Introduction
What follows is a short history that focuses on a single aspect of the JavaScript language — the Array Object — through the major language milestones, using it as a lens through which to view how JavaScript has evolved from its origins as a ‘toy language’ for browsers into a more powerful general-purpose programming language.
In the year 2018 we’ve grown familiar with an Array Object that provides us with a healthy set of tools that the language contains for working with arrays. JavaScript has methods for simple array manipulation, like push
and concat
, and more complex ‘functional programming’ style methods, like map
and reduce
. Yet for much of JavaScript’s history, the Array Object had very little built-in. Those looking to use JavaScript for serious development were forced to use outside frameworks and libraries like MooTools, Prototype or Lodash that added a lot of basic functionality. Much of that functionality has now been incorporated into the language, which has decreased the need for such frameworks.
JavaScript’s history is a bit muddled; almost immediately after its inception at Netscape, it became cloned and implemented by Microsoft as JScript. Later all other browsers would also implement JavaScript on their own terms, and different browsers have experimented with different non-standard features over the years, so in many cases array methods had been available in specific implementations of the language but not universally available. The cleanest milestones have been the ECMA standards, which have always set a minimum bar for common JavaScript features across browsers, so this history will focus on those milestones.
JavaScript 1.0 December 1995 (Netscape 2)
We’ve all heard the story of Brendan Eich creating the prototype of JavaScript — at the time, LiveScript — over 10 days. While this was an extraordinary achievement, it did mean that the very first version lacked a lot of things that we now consider basic to the language. JavaScript 1.0 had absolutely no built in functionality for dealing with arrays — the Array Object simply did not exist. Netscape documentation did provide you with the function in case you wanted to hand-craft some arrays:
function initArray() {
this.length = initArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i]
}
But that was it.
Javascript 1.1 August 1996 (Netscape 3)
The protagonist of this narrative is the Array Object, and in less than a year later, in JavaScript 1.1 it was born (along with some friends, the Boolean, Function and Number Objects.) The Array Object was also given a small set of methods: join
, reverse
, sort
and split
.
JavaScript 1.2 June 1997
At this point Netscape added two new methods —concat
and slice
. And perhaps more importantly, it introduced an array literal notation that we still use today, inspired by Python.
ECMA 1 (Javascript 1.3)
In 1997, Netscape approached ECMA to take over as the standards body regulating the language, ensuring common JavaScript code would always be able to operate across browsers. ECMA released its first standard in June 1997.
The Array Object in its original ECMA incarnation only contained the following methods: constructor
, toString
,join
, reverse
, sort
. The ECMA 1 standard did not contain all of JavaScript’s methods from 1.2 or some new methods that became available on Netscape’s JavaScript 1.3. concat
, pop
, push
, shift
, slice
and splice
were all missing as well as the Index and Input properties. It also did not contain array literals. During this period, Netscape made some other minor changes with its own release of version 1.3; the length of an array became an unsigned, 32-bit integer, push
now returned the element added to the array instead of the new array, and splicing one returned an array of one thing instead of the element.
ECMA 3 March 2000 (Javascript 1.5)
While EcmaScript 2 was a fairly minor editorial update, EcmaScript 3 was a larger step forward that provided a standard that would last for nearly a decade of web development. ECMA 3 included all of the above methods that had been developed for JavaScript 1.3, along with array literals. The EcmaScript 3 standard included the following methods on the Array Object: toString
,sort
, splice
, unshift
, toLocaleString
, concat
,join
, pop
,push
,reverse
,shift
and slice
.
The years that followed ECMA 3 were JavaScript’s awkward teenage years — there wasn’t another formal ECMA standard for almost a decade, so in some ways the language was changing very slowly. This was in part due to Microsoft’s browser monopoly — there’s less of a drive for standardization when one company controls the market, and Microsoft had its own business incentives not to push JavaScript too hard.
But during this period two major things were happening:
- Firefox (rising from the ashes of Netscape) started eroding Microsoft’s market share, and the browser wars began anew.
- The birth and growth of Ajax. An overlooked JavaScript function called
XMLHttpRequest
that was originally included by Internet Explorer ended up spurring a new age of web development, starting with Gmail and Google Maps.
In the late 2000s, JavaScript had never been so important, yet the actual standards still had yet to evolve. JavaScript 1.6 (now released for Firefox 1.5) was released November 29, 2005 and which included a set of methods then known as ‘Array Extras’ — useful iterative methods like forEach
and map
. But they were, at the time, only available on Firefox.
During this period there was an extended debate over the future of JavaScript for EcmaScript 4 — some pushing for an enormous package of new features to be added to the language, others (most notably Microsoft) expressing concerns about security and bloat. The EcmaScript 4 battle ended with an impasse and it was never released. The less controversial features were packaged together as EcmaScript 3.1.
EcmaScript 5–2009
EcmaScript 3.1 was eventually renamed EcmaScript 5 and while far less ambitious in scope than EcmaScript 4, was still a fairly large development, given that the language standards hadn’t advanced for a decade. The “Array extras” were now officially part of the language, which helped reduce dependence on external libraries. The methods every
,filter
,forEach
, indexOf
, lastIndexOf
, map
,reduce
and some
were all added to the Array Object.
ECMAScript 2015 (EcmaScript 6)
EcmaScript 2015 was the last massive release for the language. Having learned from the EcmaScript 4 debacle, TC39 (the committee that develops JavaScript standards) decided that future releases would be smaller and yearly. This would both ensure that the language would never suffer another lost decade as it did between Ecma 3 and Ecma 5, and also that the committee would never again be warring over a massive package of features at once, as it did for Ecma 4. The yearly release cycle also meant that the updates would be renamed — although this version of the standard is still frequently referred to as EcmaScript 6, the proper title is in fact EcmaScript 2015.
What did this update mean for Arrays? Quite a bit actually. The array object gained a swath of new methods: entries
,keys
, values
,find
,findIndex
, fill
andcopyWithin
. It also gained two class methods, Array.from
— which allows us to turn other objects into arrays (a common target being the almost-but-not-arrays such as ‘arguments’) and Array.of
, a slightly different array constructor. The Array Object also got some new friends, designed for dealing with raw binary data, Typed Arrays. While not formally of type Array, Typed Arrays share most of its methods. The convention ‘Iterable’ was also introduced to the language, and Arrays were included as an iterable data source — giving arrays access to the new spread operator among other things.
ECMAScript 2016 and on
As the first minor standards release, EcmaScript 2016 did not change Arrays much — the only update was a minor inclusion, Array.prototype.includes
. One could already approximate this method usingarr.indexOf(x) >= 0
, but includes
is a more comprehensible way of writing it. (There are some other minor differences.) ECMAScript 2017 did not include any major updates for arrays.
What does the future hold for fans of JavaScript arrays? Well, the TC39 process is completely public, so it’s actually pretty easy to find out. https://github.com/tc39/proposals. There is one thing in the works: Array.prototype.flatMap
and Array.prototype.flatten
, which will help flatten nested arrays. These things are currently listed as Stage 3 of the 4 step process, which means that the proposal has been fully developed and just needs to be implemented and tested in the real world before TC39 can agree on its inclusion in the standard.
Overall, the major updates made during ES5 and ES2016 really did fill a lot of the obvious gaps when it came to array functionality. That there isn’t much in the pipeline is in some ways a good thing — today’s Javascript gives programmers the necessary tools for working with this crucial data structure.
We can see this by looking at the frameworks popular with developers over the years — while in the past the most popular libraries were mostly just there to fill in the gaps in the language, today’s popular frameworks like React and Angular go far beyond patching up holes and instead provide JavaScript developers with the ability to produce complex web applications.