In the above example, create a class Array which contains two properties i.e. length and data, where length will store the length of an array and data is an object which is used to store elements.
Function in Array: There are many functions in array which are listed below:
Push(element): This function is used to push an element at the end of the array.
Pop(): It is used to delete an element at the end of the array.
In the above example, item variable will store the last element from data object and perform deletion of last element and then, it will decrease the length of by 1 and return the object.
insertAt(): This function is used to insert an element at given index.
This function accepts two parameters item and index. Index number denoting the place where data to be inserted and item is the value which is to be inserted at index.
deleteAt(index): This function is used to remove an element at given index or property in a data object.
In above function, use loop to reach at index till the end, and copy the next element at index and at the end of loop two copies of last element exist, delete last element through delete operator.
getElementAtIndex(index): It returns the element at given index.
Example: This function describes the implementation of array class and its various operations.
- How to find the parent class name with known class in jQuery ?
- How to override the CSS properties of a class using another CSS class ?
- Difference between Class.method and Class.prototype.method
- Queue | Set 1 (Introduction and Array Implementation)
- Prefix Sum Array - Implementation and Applications in Competitive Programming
- Binary Tree (Array implementation)
- Implementation of Dynamic Array in Python
- Find the smallest positive number missing from an unsorted array : Hashing Implementation
- Implementation of lower_bound() and upper_bound() in Array of Pairs in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.