B
B
bzotsss2021-07-11 17:18:53
JavaScript
bzotsss, 2021-07-11 17:18:53

How to compare the current array element with the next one?

Hello everyone, how to compare the current element of an array with the next one? now the problem is that the last subsequent e-mail. - undefined .
Here is the code

for(let i = 0;i<arr.length;i++){
        console.log(arr[i],arr[i + 1])
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2021-07-11
@bzotsss

Before comparing, check that the next element!== undefined

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question