I’m trying to print array elements 1st and 2nd in one line, then next line 2nd and 3rd elements, but I’m still stuck.
Input:
const arr = [10, 20, 30, 40, 50];
Output
10 - 20
20 - 30
30 - 40
40 - 50
>Solution :
for (let i = 0; i < arr.length - 1; i ++) {
console.log(arr[i] + ' - ' + arr[i+1]);
}
but I’d recommend using the syntax
console.log(`${arr[i]} - ${arr[i+1]}`)