Loop

Wants to get some data from Database by loop, like…

console.log(presetsDATA.items[0].refDD1)
console.log(presetsDATA.items[0].refDD2)
console.log(presetsDATA.items[0].refDD3)
console.log(presetsDATA.items[0].refDD4)
console.log(presetsDATA.items[0].refDD5)

How to loop this?

Do not work.

for (var i = 0; i <10; i++) {
    console.log(presetsDATA.items[0].("refDD"+i))
}

also tried this one…

let refFields = []
    refFields[0] = "refDD1"
    refFields[1] = "refDD2"
    refFields[2] = "refDD3"
    refFields[3] = "refDD4"

for (var i = 0; i <10; i++) {
    console.log(presetsDATA.items[0].refFields[i])
}

What is the right way?

for (var i = 0; i < 10; i++) {
    console.log(presetsDATA.items[0]["refDD"+ i]);
}

Nice! Thanks J.D.! I could not figure out the right syntax. :sleepy:
I hope i can memorize this for all my life! Always the same problems :grin:.

So i do NOT NEED the POINT between “items[0]” and " [ “refDD” + i ]" ???
OK!

That’s a much more simple way, then i was thinking of! You have my LIKE! :heartpulse:

Exactly. In such cases you can’t use the dot notation.

@jonatandor35 This was my problem. I always tried it —> with <— the dot. Damn! :laughing:
I already was searching many times for exactly this solution one, because i am often in this situation, try to make my code much more flexible and it was always this little one missing knowlegde, which made my coding make difficult.

I have a " deja-vu "! Last time i think it was also you, when you showed me a new coding-technique and i said —> " right now i am going to upgrade my coding-style "

The result was the beginning of my SUPER-FILTER-ENGINE, now i can hoppely improve it even much more, by using this new coding-knowledge.

So keep in mind → every little extra-tip made by you, blows up my project a lot!
Thanks for this!

P.S.: I could integrate already some new coding skills → the first sign of life of the “DB-SWITCHING-FUNCTION” can be seen here…
https://www.media-junkie.com/pflegeservice

And one day, you will see the end-result and all the integrated features of my SUPER-FILTER-ENGINE :grin::grin::grin:.

See you my friend.:wink:

EDIT: At the current state, i just have 2-fixed integrated EXAMPLE-DATABASES in this example:

  1. Data-Collection: —> “Worlds-Presidents”
  2. Data-Collection: —> “Team”

But i think you will recognize by yourself what i am trying to accomplish :smile:

(I’m tired of creating every time a new filter with CODE over and over again for several pages. Soon this will work for all my sites :sunglasses:)