Array At - In 2 Minutes - JavaScript

Поделиться
HTML-код
  • Опубликовано: 1 июл 2024
  • The array "at" method in JavaScript lets you access an element at a specific index and supports negative indices.
    For your reference, check this out:
    developer.mozilla.org/en-US/d...
    🏫 My Udemy Courses - www.udemy.com/user/domenic-co...
    🎨 Download my VS Code theme - marketplace.visualstudio.com/...
    💜 Join my Discord Server - / discord
    🐦 Find me on Twitter - / dcodeyt
    💸 Support me on Patreon - / dcode
    📰 Follow me on DEV Community - dev.to/dcodeyt
    📹 Join this channel to get access to perks - / @dcode-software
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #javascript #jsin2minutes

Комментарии • 8

  • @suelingsusu1339
    @suelingsusu1339 12 дней назад

    🙏🙏🙏👌👌👌🖖🖖🖖🖖🖖🖖🌹🌹🌹🌹

  • @user-dx3zu9pt7n
    @user-dx3zu9pt7n 11 дней назад +2

    thanks, i want to point another difference :
    let a=[34,56,76,87];
    a[-2]=999;
    console.log( a.at(-2) ); //76
    console.log( a[-2] ); //999

    • @webad8770
      @webad8770 11 дней назад

      🤡

    • @batchrocketproject4720
      @batchrocketproject4720 11 дней назад +1

      yes, care needed. The -2 'element' is not an element but a key of object 'a' (js arrays are also objects). adding keys that way doesn''t change the array length and the key's value (999 here) is ignored when iterating arrays with array methods.

    • @user-dx3zu9pt7n
      @user-dx3zu9pt7n 11 дней назад

      @@batchrocketproject4720
      Yup :) 👍

  • @SilentBlueDragon
    @SilentBlueDragon 12 дней назад

    You neglected to demonstrate what happens when you go past the limit in the negative direction.
    For example:
    result = [ 'dcode', 'new.user.91', 'CodingMan' ].at( -5 );
    returns undefined

    • @dcode-software
      @dcode-software  12 дней назад

      Good to know that it returns undefined when you go out of range with a negative index as well