Edit: My brain is about done for tonight but as I blankly stare at your question trying to figure out what you are trying to do and why you are trying to do it I started to think of a potential approach that is better than my current answer.
If the letter values are static, what you really care about is building a matrix based on the numbers. If you have [2,3] you want a two by three matrix with static letters in between. If you have a [3,3] you want a matrix of 9 rows of 2 items. [2,3,2] would be 12 rows of 3 items.
So if that's a correct assumption [2,"a","b",3,"c",2] would end up looking something like:
[1,1,1]
[1,1,2]
[1,2,1]
[1,2,2]
[1,3,1]
[1,3,2]
[2,1,1]
[2,1,2]
[2,2,1]
[2,2,2]
[2,3,1]
[2,3,2]
Then adding the static content back in:
[1,"a","b",1,"c",1]
[1,"a","b",1,"c",2]
[1,"a","b",2,"c",1]
[1,"a","b",2,"c",2]
[1,"a","b",3,"c",1]
[1,"a","b",3,"c",2]
[2,"a","b",1,"c",1]
[2,"a","b",1,"c",2]
[2,"a","b",2,"c",1]
[2,"a","b",2,"c",2]
[2,"a","b",3,"c",1]
[2,"a","b",3,"c",2]
Is that remotely what you're looking for? Are the letters irrelevant other than that they need to show up in the final output?
Here's where I'm leaving off for tonight:
const data = [2, "a", "b", 3];
// Find the numbers
const numericData = data.filter(item => typeof item === 'number');
console.log(numericData); // [2,3]
// Build the matrix
const matrix = Array(2).fill()
.map(()=>Array(3).fill(0));
console.table(matrix);
// Populate the matrix
// Add static content back in
Original answer:
There's got to be a better way but here's one way.
const data = [2, "a", "b", 3];
let output = [];
for (let x = 1; x <= data[0]; x++) {
for (let y = 1; y <= data[3]; y++) {
output.push([x, "a", "b", y]);
}
}
console.log(output);
Yields:
[
[1,"a","b",1],
[1,"a","b",2],
[1,"a","b",3],
[2,"a","b",1],
[2,"a","b",2],
[2,"a","b",3]
]
[1, c, 4, d, e, 2]??[-5, c]??