{"id":6659,"date":"2025-01-15T07:21:49","date_gmt":"2025-01-15T07:21:49","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=6659"},"modified":"2025-05-16T04:11:09","modified_gmt":"2025-05-16T04:11:09","slug":"how-to-insert-item-into-js-array-at-specific-index","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/","title":{"rendered":"How to Insert Item Into JS Array At Specific Index"},"content":{"rendered":"\n<p>Web developers commonly use JavaScript arrays to store data. They are very popular, offer lots of features and are easy to use. Often, we need to insert one or more items into existing JavaScript arrays. Generally, people need to <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-append-items-to-js-array\/\">append items to JS array<\/a> or <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-add-new-elements-to-beginning-of-array-in-javascript\/\">add items to beginning of array<\/a>. But sometimes you may need to insert items at specific index. There are several ways to do this using JavaScript. In this article, we will learn how to insert item into JS array at specific index.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#How_to_Insert_Item_Into_JS_Array_At_Specific_Index\" >How to Insert Item Into JS Array At Specific Index<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#1_Using_Splice\" >1. Using Splice<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#2_Using_toSpliced\" >2. Using toSpliced<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#3_Using_Prototype_Function\" >3. Using Prototype Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#4_For_pre_ES6_browsers\" >4. For pre ES6 browsers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#5_Using_Spread_Operator\" >5. Using Spread Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Insert_Item_Into_JS_Array_At_Specific_Index\"><\/span>How to Insert Item Into JS Array At Specific Index<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us say you have a simple JavaScript array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 3, 4, 5];<\/pre>\n\n\n\n<p>Let us look at some of the easy to ways to insert item into a JS array, at specific index.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Splice\"><\/span>1. Using Splice<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Splice() is a popular JS function that adds\/removes items from an array. It modifies the original array instead of creating a new array. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">array.splice(index, count, item1, item2, ...)<\/pre>\n\n\n\n<p>In the above code, index is the position where we want to add\/remove one or more items. It starts from 0. Negative value will start the index from end. Count is an optional argument for the number of items to be removed Thereafter, you can provide one or more items in a comma-separated manner, to be added.<\/p>\n\n\n\n<p>Depending on the values supplied, splice() function will first remove <em>count<\/em> number of items at <em>index<\/em>, and insert the specified items at the same position. <\/p>\n\n\n\n<p>Since we only want to insert item at specific index, we mention count=0. Here is an example to insert item=6 at position=3.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.splice(3, 0, 6); <br>console.log(a);  \/\/ output is [1, 2, 3, 6, 4, 5]<\/pre>\n\n\n\n<p>If you want to insert multiple items, say, 6, 8, 9, then mention them one after the other, in a comma-separated manner.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.splice(3, 0, 6, 8, 9); <br>console.log(a);  \/\/ output is [1, 2, 3, 6, 8, 9, 4, 5]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_toSpliced\"><\/span>2. Using toSpliced<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>As mentioned above, splice() function will modify the original array. If you do not want that to happen, and want the result to be stored in a new array, then you can use toSpliced() function. Its syntax is exactly same as that of splice() function. You can use it to add\/remove one or more items in an array. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">array.toSpliced(index, count, item1, item2, ...)<\/pre>\n\n\n\n<p>In the above code, we need to specify the <em>index<\/em> position as the first argument. It starts from 0. Like splice(), using negative value starts the count from end. Thereafter, you need to mention the count of items to be removed. It is optional. We we will mention it as 0, since we need to insert and not remove items from our array. After that, you can specify the items to be inserted, one after the other, in a comma-separated manner.<\/p>\n\n\n\n<p>Here is an example to insert item=6 at position=3.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">b=a.toSpliced(3,0,6)<br>console.log(b); \/\/ [1, 2, 3, 6, 4, 5]<br>console.log(a); \/\/ [1, 2, 3, 4, 5]<\/pre>\n\n\n\n<p>As you can see above, the original array a remains unchanged. Its result is stored in another array b.<\/p>\n\n\n\n<p>You can also use toSpliced() function to insert multiple items.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">b=a.toSpliced(3,0,6,8,9)<br>console.log(b); \/\/ [1, 2, 3, 6, 8, 9, 4, 5]<br>console.log(a); \/\/ [1, 2, 3, 4, 5]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_Prototype_Function\"><\/span>3. Using Prototype Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can use either of the above mentioned functions to create a prototype function that inserts one or more items at a given index position in an array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Array.prototype.insert = function ( index, ...items ) {<br>    this.splice( index, 0, ...items );<br>};<\/pre>\n\n\n\n<p>In the above code, we have created prototype function insert(), that accepts 2 arguments &#8211; index position and a comma-separated list of items (&#8230;item). Please note, we have used spread operator (&#8230;) to accommodate one or more items. We have already set count=0 in splice() function. Here is how to use it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.insert(3, 6);<br>console.log(a); \/\/ output is [1, 2, 3, 6, 4, 5]<\/pre>\n\n\n\n<p>Once you have defined the above prototype function, you can directly call it on all arrays on your web page.<\/p>\n\n\n\n<p>If you do not want to modify the original array but want to store result in a new array, then you can use toSpliced() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Array.prototype.insert = function ( index, ...items ) {<br>    return this.toSpliced( index, 0, ...items );<br>};<br><br>b = a.insert(3, 6);<br>console.log(b); \/\/ [1, 2, 3, 6, 4, 5]<br>console.log(a); \/\/ [1, 2, 3, 4, 5] <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_For_pre_ES6_browsers\"><\/span>4. For pre ES6 browsers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>All the above solutions work for ES6 compliant web browsers, that is, modern web browsers. However, if you or your users use very old web browsers that are pre-ES6, then you will need to use a different approach. In this case, you can slice() function that allows you to split an array. You can directly call it on all arrays. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">array.slice(start_index, end_index);<\/pre>\n\n\n\n<p>In the above code, we need to specify the start and end index positions. If you use negative indexes, then JavaScript will start counting from the end. If no end index is specified, then the default is the last position.<\/p>\n\n\n\n<p>We will use this function to insert an item into an array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function insert(array, index) {<br>  const items = Array.prototype.slice.call(arguments, 2);<br>  return [].concat(array.slice(0, index), items, array.slice(index));<br>}<\/pre>\n\n\n\n<p>In the above function, we take 2 arguments &#8211; the array and index. In fact, the index itself contains the index position to be inserted as well as the items to be inserted. We call slice() function on the arguments keyword that stores the input arguments as an array, to get the item value(s) presend after secodnd argument. First, we extract items from the input arguments. Please note, we could have used spread operator to supply items (&#8230;items) as the 3rd argument of insert function but spread operator is supported only in ES6 browsers.<\/p>\n\n\n\n<p>Then we use concat() function to concatenate the part of array before index, the item to be inserted and the part of array after the index. We use slice() function twice &#8211; to get the part of array from beginning to index position, and to get the part of array from the index till the end.<\/p>\n\n\n\n<p>You can call the insert() function as shown.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">b=insert(a, 3, 6);<br>console.log(b); \/\/ [1, 2, 3, 6, 4, 5]<br>console.log(a); \/\/ [1, 2, 3, 4, 5]<\/pre>\n\n\n\n<p>You can also call this function with multiple items.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">b=insert(a, 3, 6, 8);<br>console.log(b); \/\/ [1, 2, 3, 6, 8, 9, 4, 5]<br>console.log(a); \/\/ [1, 2, 3, 4, 5]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_Spread_Operator\"><\/span>5. Using Spread Operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Spread operator is a versatile operator in JavaScript that allows you to easily concatenate arrays. It is also used to easily copy part of array or object into another array or object. It is also used for deconstructing arrays but that is not relevant here. It is supported by all ES6 web browsers and can be easily used to insert one or more items into a JS array at specific index.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function insert(array, index, new_items)<br>{<br>    return [...array.slice(0, index), ...new_items, ...array.slice(index)];<br>}<\/pre>\n\n\n\n<p>In the above code, function insert() accepts 3 arguments &#8211; the original array, the index position to insert item, and the actual item(s) to be inserted. We use slice() function mentioned earlier to extract part of array from start to index position. We also use slice() function to extract part of array from index position to end of array. Lastly, we use spread operator to concatenate the first part of array, new items and the last part of array.<\/p>\n\n\n\n<p>You can use it as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">b=insert(a, 3, [6]);<br>console.log(b); \/\/ [ 1, 2, 3, 6, 4, 5 ]<br>console.log(a); \/\/ [ 1, 2, 3, 4, 5 ]<\/pre>\n\n\n\n<p>Please note, in the above code, you need to pass the item(s) to be inserted as array. So this is very useful if the item you want to insert itself is an array. It will seamlessly insert all items of the array into original array.<\/p>\n\n\n\n<p>If you want to simply mention them in a comma-separated manner, you can use slice() function on arguments array to extract the items.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function insert(array, index)<br>{<br>    const items = Array.prototype.slice.call(arguments, 2);<br>    return [...array.slice(0, index), ...items, ...array.slice(index)];<br>}<br>b=insert(a, 3, 6, 8, 9);<br>console.log(b); \/\/ [ 1, 2, 3, 6, 8, 9, 4, 5 ]<br>console.log(a); \/\/ [ 1, 2, 3, 4, 5 ]<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt how to insert item in a JavaScript array at specific index. We have tried to cover several diverse use cases instead of providing multiple ways of doing the same thing. Please note, although we have used numerical array for all our examples, they can be used for all data types in an array. You can use any of these solutions depending on your requirement.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/what-does-strict-do-in-javascript\/\">What Does Strict Do in JavaScript?<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\">How to Check If Array Includes Value in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-move-element-into-other-element-in-jquery\/\">How to Move Element to Other Element in jQuery<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to insert items into JavaScript array. Here is how to insert item into JS array at specific index.<\/p>\n","protected":false},"author":1,"featured_media":6689,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[375],"class_list":["post-6659","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-insert-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Insert Item Into JS Array At Specific Index - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to insert items into JavaScript array. Here is how to insert item into JS array at specific index.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Insert Item Into JS Array At Specific Index - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to insert items into JavaScript array. Here is how to insert item into JS array at specific index.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-15T07:21:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-16T04:11:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/insert-item-into-js-array-specific-index.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"301\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Insert Item Into JS Array At Specific Index\",\"datePublished\":\"2025-01-15T07:21:49+00:00\",\"dateModified\":\"2025-05-16T04:11:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/\"},\"wordCount\":1210,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1\",\"keywords\":[\"insert item\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/\",\"name\":\"How to Insert Item Into JS Array At Specific Index - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1\",\"datePublished\":\"2025-01-15T07:21:49+00:00\",\"dateModified\":\"2025-05-16T04:11:09+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to insert items into JavaScript array. Here is how to insert item into JS array at specific index.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1\",\"width\":301,\"height\":200,\"caption\":\"insert item into js array at specific index\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-insert-item-into-js-array-at-specific-index\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Insert Item Into JS Array At Specific Index\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Insert Item Into JS Array At Specific Index - Ubiq BI","description":"Sometimes you may need to insert items into JavaScript array. Here is how to insert item into JS array at specific index.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/","og_locale":"en_US","og_type":"article","og_title":"How to Insert Item Into JS Array At Specific Index - Ubiq BI","og_description":"Sometimes you may need to insert items into JavaScript array. Here is how to insert item into JS array at specific index.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-01-15T07:21:49+00:00","article_modified_time":"2025-05-16T04:11:09+00:00","og_image":[{"width":301,"height":200,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/insert-item-into-js-array-specific-index.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Insert Item Into JS Array At Specific Index","datePublished":"2025-01-15T07:21:49+00:00","dateModified":"2025-05-16T04:11:09+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/"},"wordCount":1210,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1","keywords":["insert item"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/","name":"How to Insert Item Into JS Array At Specific Index - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1","datePublished":"2025-01-15T07:21:49+00:00","dateModified":"2025-05-16T04:11:09+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to insert items into JavaScript array. Here is how to insert item into JS array at specific index.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1","width":301,"height":200,"caption":"insert item into js array at specific index"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Insert Item Into JS Array At Specific Index"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/insert-item-into-js-array-specific-index.jpg?fit=301%2C200&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Jp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=6659"}],"version-history":[{"count":32,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6659\/revisions"}],"predecessor-version":[{"id":8205,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6659\/revisions\/8205"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/6689"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=6659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=6659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=6659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}