Logo
Pattern

Discover published sets by community

Explore tens of thousands of sets crafted by our community.

Array Methods and Properties

10

Flashcards

0/10

Still learning
StarStarStarStar

push()

StarStarStarStar

Adds one or more elements to the end of an array and returns the new length of the array. Complexity: O(1) amortized.

StarStarStarStar

pop()

StarStarStarStar

Removes the last element from an array and returns that element. Complexity: O(1).

StarStarStarStar

shift()

StarStarStarStar

Removes the first element from an array and returns that removed element. Complexity: O(n) as it may require shifting all other elements.

StarStarStarStar

unshift()

StarStarStarStar

Adds one or more elements to the beginning of an array and returns the new length. Complexity: O(n) as it may require shifting all other elements.

StarStarStarStar

slice()

StarStarStarStar

Returns a shallow copy of a portion of an array into a new array object. Complexity: O(n), where n is the number of elements in the selected range.

StarStarStarStar

splice()

StarStarStarStar

Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. Complexity: O(n), due to the need to shift elements.

StarStarStarStar

concat()

StarStarStarStar

Used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array. Complexity: O(n), where n is the total number of elements in the combined arrays.

StarStarStarStar

indexOf()

StarStarStarStar

Returns the first index at which a given element can be found in the array, or -1 if it is not present. Complexity: O(n), where n is the array length.

StarStarStarStar

sort()

StarStarStarStar

Sorts the elements of an array in place and returns the array. The default sort order is according to string Unicode code points. Complexity: O(n log n), on average, depending on the implementation.

StarStarStarStar

length

StarStarStarStar

The length property of an array represents the number of elements in the array. Complexity: O(1), as it is just accessing a property.

Know
0
Still learning
Click to flip
Know
0
Logo

© Hypatia.Tech. 2024 All rights reserved.