D
D
Dubolom Unicellular2020-05-05 15:41:00
JavaScript
Dubolom Unicellular, 2020-05-05 15:41:00

How to select last letter of text using js loop?

How do I select (iterate through) the last letter of a text using a loop?
There is such a structure:

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor, 2020-05-05
@duboloms

Do you need a cycle? You can do this: But if you need a loop, then for in is not very suitable in my opinion.
let endChar = $("h1").text().substr(-1);

let text = $("h1").text();

for(let i = 0; i < text.length; i++){
  if (i == text.length - 1) console.log(text[i]);
}

N
n1ksON, 2020-05-05
@n1ksON

https://jsfiddle.net/niks_on/Lkmosnzy/

R
Rerurk, 2020-05-05
@Rerurk

text=text.slice(0, -1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question