Programming/JavaScript/Objects and Data Structures: Difference between revisions
< Programming | JavaScript
Jump to navigation
Jump to search
Brodriguez (talk | contribs) (Import from other page) |
Brodriguez (talk | contribs) m (Brodriguez moved page JavaScript/Objects and Data Structures to Programming/JavaScript/Objects and Data Structures) |
(No difference)
|
Revision as of 22:59, 22 February 2023
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>);