How do I find out the next element from for?

  • 0
    Hello! Please tell me how I can find out the next element from the for loop.

    I have a DOM document where I get all elements with data-sort.
    I also know the value of data-sort = 10, how can I get the next value?

    const sort = event.clone.dataset['sort'] // Здесь я знаю свой элемент который перетаскиваю data-sort = 10
          var a = this.$refs['draggable-area'].$el.querySelectorAll('[data-sort]'); // Здесь я получаю весь список элементов с data-sort
          for (var i in a) if (a.hasOwnProperty(i)) {      // Здесь я сделаю цикл, чтобы вывести все по порядку

    This is what I get with console.log output

    I need to get the next value from a value that I already know. In this case, if I know 10, I should somehow find out 12

    Thanks in advance
    JavaScript Lily Snow, Jul 2, 2020

  • 1 Answers
  • 0
    console.log('current:', a[i].getAttribute('data-sort'), 'next:', a[i+1].getAttribute('data-sort')||null);

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!