📋 Table Of Content
index at which you want the item to be added.
To solve this we can go head with approaches using
splice() method overwrites the original array.
splice(start, deleteCount, item1)
start : The index at which the content will change
deleteCount: It mean the number of elements that will be removed from the start index. If it is 0 (zero) or negative, it means no elements will be removed.
item1 : The element that will be added in the array.
Lets check it with an example.
const months = ['Jan', 'March', 'April', 'June']; months.splice(1, 0, 'Feb'); console.log(months)
["Jan", "Feb", "March", "April", "June"]
Here we have added 'Feb' in index 1 in the array.
Note: In Array the
- Check for prime number using for and while loop in Python
- Merge two dictionaries together using python (3 ways)
- Merge multiple JSON objects into one single object in Python
- Python - Check if list is empty or not
- Python - Insert an element at specific index in a list