Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / structures

JavaScript Supports Four Types of Basic Data Structures

4.00/5 (8 votes)
4 Mar 2015CPOL1 min read 9.3K  
The four types of basic data structures supported by JavaScript are: array lists, maps, records and JSON tables.

The four types of basic data structures supported by JavaScript are: array lists, maps, records and JSON tables. The following list provides a summary:

  1. Array lists, such as ["one","two","three"], are special JS objects called 'arrays', but since they are dynamic, they are rather array lists as defined in the Java programming language.

  2. Maps are also special JS objects, such as {"one":1,"two":2,"three":3}, as discussed below.

  3. Records, such as {firstName:"Tom",lastName:"Smith"}, are also special JS objects, as discussed below.

  4. JSON tables are special maps where the values are records representing entities (with a primary key slot), and the keys are the primary keys of these entity records (for an example of such a table, see  Storing database tables in JavaScript's Local Storage).

Notice that our distinction between maps, records and JSON tables is a purely conceptual distinction, and not a syntactical one. For a JavaScript engine, both {firstName:"Tom",lastName:"Smith"} and {"one":1,"two":2,"three":3} are just objects. But conceptually, {firstName:"Tom",lastName:"Smith"} is a record because firstName and lastName are intended to denote properties or fields, while {"one":1,"two":2,"three":3} is a map because "one""two" and "three" are not intended to denote properties/fields, but are just arbitrary string values used as keys in a map.

Making such conceptual distinctions helps to better understand the options offered by JavaScript.

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)