Programming/JavaScript/Objects and Data Structures
< Programming | JavaScript
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>);