A javascript eq (index) jQuery analog?

  • 0
    Can you please tell me an analogue of the JQuery eq (index) method, but in pure JavaScript?
    JavaScript Anonymous, May 28, 2019

  • 2 Answers
  • 0
    document.querySelectorAll('.class-1.class-2')[index].innerHTML = 'text';
    Anonymous

  • 0
    NodeList.prototype.eq = function(index) {
    return this[index] ? this[index] : null;
    }


    application

    <p>test</p>
    <p>test 2</p>


    document.querySelectorAll('p').eq(1) // <p>test 2</p>
    document.querySelectorAll('p').eq(100) //null
    Anonymous

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