You can use the method sliceto split the array strinto 2: part before the insertion point and part after:
var before = str.slice(0,2);
var after = str.slice(2);
Then you can use the method concatto create an array strNum, combining arrays before, numand afterinto one:
var strNum = before.concat(num).concat(after);
var str = ['a','b','c','d'];
var num = [1,2,3];
var before = str.slice(0,2);
var after = str.slice(2);
var strNum = before.concat(num).concat(after);
console.log(strNum);
Run code source
share