Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Add an element to an array at a specific index with JavaScript

const sidebarMenu = ['home', 'about', 'contact'];
sidebarMenu.splice(2, 0, 'courses'); //Add Single Element
sidebarMenu.splice(2, 0, 'courses', 'profile'); //Add Multiple Elements
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Add #element #array #specific #index #JavaScript
ADD COMMENT
Topic
Name
5+6 =