Вы можете использовать методы Array#map
и Array#splice
.
let arr1 = ["Diesel", "Solar", "Biomass"],
arr2 = [
["ABC", "Nigeria", "Diesel,Solar", 35],
["DEF", "Egypt", "Solar,Diesel", 50],
["GHI", "Ghana", "Biomass,Diesel", 70]
];
// iterate over the array
let res = arr2.map((arr, i) => {
// copy array values to a new array
let newA = [...arr];
// insert new element into array based on index
newA.splice(3, 0, arr1[i]);
// return new array
return newA;
})
console.log(res)
Если вы хотите изменить исходный массив, то можете пропустить часть копирования массива, и достаточно просто метода Array#splice
.
let arr1 = ["Diesel", "Solar", "Biomass"],
arr2 = [
["ABC", "Nigeria", "Diesel,Solar", 35],
["DEF", "Egypt", "Solar,Diesel", 50],
["GHI", "Ghana", "Biomass,Diesel", 70]
];
// iterate over the array and put the value at specific index
arr2.forEach((arr, i) => arr.splice(3, 0, arr1[i]))
console.log(arr2)