数组打印元素索引 0 作为索引 1

Array print element index 0 as index 1

如何将输出打印为

1 天 17

2 天 21

3 天 23

而不是

0 天后有 17 个

1 天内 21 个

2 天 23

const arr = [17, 21, 23];

const printForecase = function() {
    for (let i = 0; i < arr.length; i++) {
        console.log(`${arr[i]} in ${i} days`);
    } } 
printForecase();

由于索引是从0开始的,所以在console.log()(${i+1})

中打印时只需要加一(1)
const arr = [17, 21, 23];

const printForecase = function() {
    for (let i = 0; i < arr.length; i++) {
        console.log(`${arr[i]} in ${i+1} days`);
    } } 
printForecase();
  1. 对嵌入表达式 ${i} 加 1 使其成为 ${i+1}
const arr = [17, 21, 23];

const printForecase = function() {
    for (let i = 0; i < arr.length; i++) {
        console.log(`${arr[i]} in ${i+1} days`);
    } } 
printForecase();

你可以用{i}加1

const arr = [17, 21, 23];

const printForecase = function() {
for (let i = 0; i < arr.length; i++) {
    console.log(`${arr[i]} in ${i+1} days`);
} } 
printForecase();

console.log(${arr[i]} in ${i+1} days)

const arr = [17,21,23];
const printForecase = ()=>{
        let days = 1;
        for(let newarr of arr){
           console.log(`${newarr} in ${ days++ } Days`)
        }
}

printForecase()