Does the JavaScript engine optimize repeated array traversal in switch cases?

Consider a scenario where a piece of JavaScript code uses a for…of loop to iterate over an array, and within that loop, a switch statement is used. Each case performs the same operation to calculate the sum of the array elements using the reduce method:

const arr = [1, 2, 3, 10, 20, 30];

for (const el of arr) {
    switch (el) {
        case 1:
            const sum1 = arr.reduce((acc, curr) => acc + curr, 0);
            // ...
            break;

        case 2:
            const sum2 = arr.reduce((acc, curr) => acc + curr, 0);
            // ...
            break;

        case 3:
            const sum3 = arr.reduce((acc, curr) => acc + curr, 0);
            // ...
            break;

        // ...

        default:
            break;
    };
};

In this example, the reduce method is called in each case to compute the sum of the array elements. My question is: does the JavaScript engine optimize this repeated traversal in any way, or will it execute the array traversal independently for each case every time?

I understand that it is possible to refactor the code to perform the array traversal outside of the loop, which would prevent the repeated traversal. However, in that case, the traversal would always occur, even when it might not be necessary (e.g., if the loop does not reach certain cases).

What are the performance implications of this approach, and how do modern JavaScript engines handle such scenarios?

I want to know how to efficiently handle repeated array traversals in multiple switch cases, especially when some cases might not need the traversal at all.