Last Updated : Jan 1, 2023
These are array.pop(), array.filter(), array.splice(), array.shift(), array.slice(). Whereas shift is used to remove array from beginning and pop is used to remove array from last and rest are used for specific index.
As, we are going to understand splice(), shift() and slice() in these couple of articles.
In this article, first we understand splice() method. So, let us begun with codes. The general syntax of splice() is given as - Array.splice(index, count, items1, ... , itemX)
- First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
- Secondly, the <html> tag is used to indicate the beginning of an HTML document.
- As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
- Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
- Here, before starting let us understand syntax of splice() first. In splice there is index, count, items1, itemX. The index specifies to the integer or say position where we want to remove or delete array. Rest are like count, items1, itemX are optional here.
- After that we to remove array we use splice on array and use (0,1) inside splice. It means that index is 0 there are count is 1.
- So, we conclude that the remove or say deletion start from first index and number of elements which we want to remove are 1. Hence, in output id 1 having name Robert must be removed from there.
- After that we use console to print or display output. You can see output by inspecting them and by opening console tab.
- At last, the <body> and <html> tags are closed with </body> and </html> respectively.