Insert Into Array
insertArray: function(array, afterIndex, item) { var first = array.slice(0, afterIndex + 1); var second = array.slice(afterIndex + 1); first.push(item); return first.concat(second); }
TextSnippets > winton > array
2741 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Winton Welsh http://stu.dicio.us
insertArray: function(array, afterIndex, item) { var first = array.slice(0, afterIndex + 1); var second = array.slice(afterIndex + 1); first.push(item); return first.concat(second); }