I’m building a tiny tagged template helper that should interleave strings and values, but only the first substitution shows up. What am I indexing wrong here?
function join(strings, ...values) {
let out = '';
for (let i = 0; i < values.length; i++) {
out += strings[i] + values[0];
}
return out + strings[strings.length - 1];
}
console.log(join`A:${1}, B:${2}, C:${3}`);
Expected: A:1, B:2, C:3
Actual: A:1, B:1, C:1
Why does this happen, and what’s the correct way to combine strings and values in a tag function?
Ellen