The thing in question in a derpy example:

JS:

var length = 5;

for ( var i = 1; i < length + 1; i++ ) {
    $( '#element' + (i -1) ).fadeOut( 500 );
    $( '#element' + i ).fadeIn( 500 );
}

HTML:

<div id="element1" style="height: 100px; width: 100px; background-color: red;"></div>
<div id="element2" style="height: 100px; width: 100px; background-color: green;"></div>
<div id="element3" style="height: 100px; width: 100px; background-color: blue;"></div>
<div id="element4" style="height: 100px; width: 100px; background-color: yellow;"></div>
<div id="element5" style="height: 100px; width: 100px; background-color: pink;"></div>

Is there a term for this? I guess the 'thing' that I'm talking about, in sentence form, is: "dynamically targetting an object in a loop by name using the incramenting loop variable as a part of the variable name you're targetting".

Probably explaining this poorly. Does anyone understand what I'm asking, and is there a 'term' for this in programming?

有帮助吗?

解决方案

The phrase that most programmers will understand is "dynamic variable name".

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top