Programming/JavaScript/Objects and Data Structures

From Dev Wiki
< Programming‎ | JavaScript
Revision as of 22:58, 22 February 2023 by Brodriguez (talk | contribs) (Import from other page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

See also Programming/JavaScript/Syntax.


Basic Data Structures

Arrays

JavaScript arrays generally handle the same as standard arrays. See Arrays for more info.

Additionally, JavaScript arrays have the following logic:

Add item to start of array:

<array_var>.unshift(<value>);

Add item to end of array:

<array_var>.push(<value>);

Remove first item in array:

removedValue = <array_var>.shift()

Remove last item in array:

removedValue = <array_var>.pop();

Return shallow copy of array. Original array is left unchanged:

arrayCopy = <array_var>.slice(<start_index>, <end_index>);

Locate index of item in array. Or -1 if not found:

index = <array_var>.indexOf(<value_to_search>, <opitonal_starting_index>);

Dictionaries

Classes