Reference for JavaScript (ECMAScript 2020)
The tables below show the syntactically highlighted topic for the language.
If you see any incorrect information, please help us improve! Feel free to either create an issue or use the link at the bottom of the language column to correct any information.
JavaScript (ECMAScript 2020)'s thesaurus is incomplete. Please help us improve by
adding or correcting information
for this language.
Ordered Mutable Lists
Concept
JavaScript's Implementation
What is a ordered (not sorted) mutable list called?
Array
Create the list
const list_name = [];
const list_name = new Array();
The first method is preferred.
What number does it start at?
0
Access element by index
list_name[index];
Insert element at beginning
list_name.unshift('new item');
list_name.splice(0, 0, 'new item');
The first method is preferred.
Insert element at end
list_name.push('new item');
list_name[list_name.length] = 'new item';
list_name.splice(list_name.length, 0, 'new item');
The first method is preferred.
Insert element in middle
list_name.splice(list_name.length / 2, 0, 'new item');
Erase first element
list_name.shift();
list_name.splice(0, 1);
The first method is preferred for this use case.
Erase last element
list_name.pop();
list_name.splice(list_name.length - 1, 1);
The first method is preferred for this use case.
Erase element in the middle
list_name.splice(list_name.length / 2, 1);
Swap two elements
Not Implemented In This Language
Delete the list
list_name = null;
list_name.length = 0;
All of these methods are acceptable.
Sorted Mutable Lists
Concept
JavaScript's Implementation
What is a sorted mutable list called?
Not Implemented In This Language
Create the list
Not Implemented In This Language
What number does it start at?
Not Implemented In This Language
Access element by index
Not Implemented In This Language
Insert element in middle
Not Implemented In This Language
Erase first element
Not Implemented In This Language
Erase last element
Not Implemented In This Language
Erase element in the middle
Not Implemented In This Language
Swap two elements
Not Implemented In This Language
Delete the list
Not Implemented In This Language
Unordered Mutable Lists
Concept
JavaScript's Implementation
What is a unordered/unsorted mutable list called?
Not Implemented In This Language
Create the list
Not Implemented In This Language
What number does it start at?
Not Implemented In This Language
Access element by index
Not Implemented In This Language
Insert element in middle
Not Implemented In This Language
Erase first element
Not Implemented In This Language
Erase last element
Not Implemented In This Language
Erase element in the middle
Not Implemented In This Language
Swap two elements
Not Implemented In This Language
Delete the list
Not Implemented In This Language
Ordered Immutable Lists
Concept
JavaScript's Implementation
What is a ordered (not sorted) immutable list called?
Not Implemented In This Language
Create the list
Not Implemented In This Language
Create the list from the mutable equivalent
Unknown
Create mutable equivalent of the list
Unknown
What number does it start at?
Not Implemented In This Language
Access element by index
Not Implemented In This Language
Delete the list
Not Implemented In This Language
Unordered Immutable Lists
Concept
JavaScript's Implementation
What is a unordered/unsorted immutable list called?
Not Implemented In This Language
Create the list
Not Implemented In This Language
Create the list from the mutable equivalent
Unknown
Create mutable equivalent of the list
Unknown
What number does it start at?
Not Implemented In This Language
Access element by index
Not Implemented In This Language
Delete the list
Not Implemented In This Language
Mutable Hashed Lists
Concept
JavaScript's Implementation
What is a mutable hashed list called?
Not Implemented In This Language
Create the list
Not Implemented In This Language
Insert an element
Not Implemented In This Language
Erase an element from the list
Not Implemented In This Language
Delete the list
Not Implemented In This Language
Immutable Hashed Lists
Concept
JavaScript's Implementation
What is an immutable hashed list called?
Not Implemented In This Language
Create the list
Not Implemented In This Language
Create the list from the mutable equivalent
Unknown
Create mutable equivalent of the list
Unknown
Delete the list
Not Implemented In This Language
Mutable Key/Value Sets
Concept
JavaScript's Implementation
Create a mutable key/value set
// Initializes an empty set
const dict_name = new Map();
dict_name.set('key', 'value');
// With an initial set
const dict_name = new Map([
['key', 'value']
]);
Get key
Not Implemented In This Language
Get value
dict_name.get('key');
Get all keys
dict_name.keys()
Returns a
MapIterator instance.
Get all values
dict_name.values()
Returns a
MapIterator instance.
Swap a key and value
Not Implemented In This Language
Delete the set
dict_name.clear();
Immutable Key/Value Sets
Concept
JavaScript's Implementation
Create an immutable key/value set
Not Implemented In This Language
Create the list from the mutable equivalent
Unknown
Create mutable equivalent of the key/value set
Unknown
Get key
Not Implemented In This Language
Get value
Not Implemented In This Language
Get all keys
Not Implemented In This Language
Get all values
Not Implemented In This Language
Swap a key and value
Not Implemented In This Language
Delete the set
Not Implemented In This Language
Find/Search Functions
Concept
JavaScript's Implementation
Get the index of an element by value
list_name.indexOf(value)
list_name.findIndex(element => element === value)
Find the minimum value in a list
Math.min(...list_name)
list_name.reduce((min, value) => value < min ? value : min)
list_name.sort((a, b) => a - b)[0]
These solutions do not have the same performance depending on the browsers. Choose from the first to the last one depending on your needs.
Find the maximum value in a list
Math.max(...list_name)
list_name.reduce((max, value) => value > max ? value : max)
list_name.sort((a, b) => b - a)[0]
These solutions do not have the same performance depending on the browsers. Choose from the first to the last one depending on your needs.
Check if the list contains a specific element
list_name.includes(value)
Convert a list to a string
list_name.join(separator)
Splitting/Joining Lists
Concept
JavaScript's Implementation
Concatenate two lists together
list_name1.concat(list_name2)
[...list_name1, ...list_name2]
list_name1.push(...list_name2)
Split lists at an index
list_name.slice(0, index)
list_name.slice(index)
The first one returns the first part of the list and the second one returns the second part of the list.
Split list at a value
list_name.slice(0, list_name.indexOf(value))
list_name.slice(list_name.indexOf(value))
The first one returns the list up to the value and the second one returns the list after the value.
Copying Lists
Concept
JavaScript's Implementation
Duplicate a list
list_name.slice()
[...list_name]
Duplicate a portion/subset of a list
list_name.slice(start, end)
Sizing/Resizing Lists
Concept
JavaScript's Implementation
Get list length
list_name.length
Check if the list is empty
Unknown
Increase/decrease list size
list_name.length = size
Remove all elements from the list
Unknown
Comparing/Equality
Concept
JavaScript's Implementation
Do two lists match every element?
list_name1.every((value, index) => value === list_name2[index])
list_name1.join() === list_name2.join()
Do two lists contain all the same items?
list_name1.every(value => list_name2.includes(value)) && list_name2.every(value => list_name1.includes(value))
list_name1.join() === list_name2.join()
Does a list satisfy some expression?
list_name.some(value => value === expression)
list_name.find(value => value === expression) !== undefined
Does a list entirely not satisfy an expression?
list_name.every(value => value !== expression)
list_name.find(value => value === expression) === undefined
Sorting/Shuffling Lists
Concept
JavaScript's Implementation
Sort a list
list_name.sort((a, b) => a - b)
Shuffle list elements
list_name.sort(() => Math.random() - 0.5)
Reverse order of list elements
list_name.reverse()
Functions On List Elements
Concept
JavaScript's Implementation
Map function across list
list_name.map(value => { /* Function body */ })
Filter a list based on criteria
list_name.filter(value => { /* Function body */ })
Reduce a list left-to-right
list_name.reduce((accumulator, value) => { /* Function body */ })
Reduce a list right-to-left
list_name.reduceRight((accumulator, value) => { /* Function body */ })
Advanced Collection Operations
Concept
JavaScript's Implementation
Get a slice/portion of a list (view or shallow copy)
Unknown
Get the first element
Unknown
Get the last element
Unknown
Remove duplicate elements from the list
Unknown
Flatten a nested list
Unknown