0

Currently I'm trying out some html and js stuff. I have trouble using a changing string inside a command with some "." in it.

for (let i = 1; i <= 2; i++) {
    let count = String("q" + i);
    console.log(document.calculate.$(this.count).value);
}

So the String "count" is changing and I want the different values of my document with the names "q1", "q2"...

Would be awesome if someone could help me. Thank You!

2
  • 2
    "bracket notation" Commented Feb 11, 2020 at 20:24
  • Thanks. That worked :) Commented Feb 11, 2020 at 21:15

2 Answers 2

1

put dinamic value in a [] quotes instead .

console.log(document.calculate[$(this.count)].value);

Sign up to request clarification or add additional context in comments.

Comments

0
for (let i = 1; i<=2; i++) {
  let count = String("q" + i);
  console.log(document.calculate.$(this[count]).value);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.