How to call a character of an array element?

  • 0
    String elements can be called their symbols, just like array elements.
    For example
    var x = 'Putin';
    console.log(x[2]);  //Выведет в консоль букву t


    Let's say I have an array.
    var array = ['rgrgr', 'fwerf', 'rngri']
    And I want to call the character of one of the elements of this array.
    var array = ['rgrgr', 'fwerf', 'rngri']
    console.log(array[0][1]);  //В консоль ничего не выведется. А я бы хотел чтобы в консоль вывелась буква g


    It is logical, first I write the number of the element in this array, and then the number of the character in this element, because the elements are string. But it doesn't want to. What's the matter?
    JavaScript Anonymous, May 4, 2019

  • 2 Answers
  • 0
    What were you thinking?

    var array = [rgrgr, fwerf, rngri]; //это переменные, а не строки


    Do this:

    var array = ['rgrgr', 'fwerf', 'rngri']; //добавили кавычки
    Anonymous

  • 0
    Everything works there, well, you better write like this.

    array [0] .charAt (1)
    Anonymous

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