Q:

How to reference a variable that consists of metavariables, which require delayed expansion, to create a one-dimensional array in Batch

OS: Windows 10, Version: 10.0.17134.112

I was trying to reference a variable that consists of a dynamic variable, which requires delayed expansion, in the form of !string!variable!!. The problem I'm facing is it is being evaluated as [!string!][variable!!] rather than ![string][!variable!]!
Here's an example of what I'm trying to do:
@echo off

setlocal EnableDelayedExpansion

::Sets variables - Items to be excluded, and an initial index number to reference these variables
set "_elem1=ex1"
set "_elem2=ex2"
set "_elem3=ex3"
set "_n=1"

::Builds a one-dimensional array excluding some items where item-set is arranged in a specific order
for %%e in (A B C ex1 D E F ex2 G H ex3 I J) do (
    if not "!_elem!_n!!"=="%%e" (
        set "_array=!_array!!_spc!"%%e""
        set "_spc= "
    ) else (
        set /a "_n+=1"
    )
)

::Displays actual output
echo %_array%

::Displays DESIRED output
echo "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"

pause

Basically, what it does, or at least what it is supposed to do, is it builds a filtered one-dimensional array of items from for item-set by running a conditional block. If "!_elem!_n!!" is not equal to "%%e", the result for the current iteration is appended to the stored value of _array variable. Otherwise, it ignores the value from the current iteration and increments the index by 1, effectively changing the value of !_elem!_n!! on the next iteration.
The problem is variable _n is dynamic and requires delayed expansion. What I'm trying to accomplish is for the variable !_elem!_n!! to be evaluated as ! _elem !_n! ! rather than !_elem! _n!!
Upon researching, I've stumbled upon these sources:

Stack Overflow - Variable Within Variable

The answers provided in the link are really valuable but the index used in the examples are not dynamic, and so, !_elem%_n%! would be fine in those situations but not if the index is dynamic. Also, a method using call was provided, which is clever, but call does not work with ifs.
I'm running out of ideas here. I'd really appreciate any ideas you could throw at this.
Thank you all very much!!

A:

Your approach had the flaw that you didn't compare each _elem with each %%e

In this batch the var Found is a flag to indicate if the current
%%e was matched by any _elem
a counting for /l is used to iterate the _elem variables.
The content of the var Found doesn't matter it's existence isn't influenced
by being set in the same (code block).

:: Q:\Test\2018\07\03\SO_51147577.cmd
@echo off & setlocal EnableDelayedExpansion
::Sets variables - Items to be excluded, and an initial index number to reference these variables
set "_elem1=ex1"
set "_elem2=ex2"
set "_elem3=ex3"
set "_spc="
::Builds a one-dimensional array excluding some items where item-set is arranged in a specific order
for %%e in (A B C ex1 D E F ex2 G H ex3 I J) do (
    Set "Found="
    For /l %%n in (1,1,3) do (
         if "!_elem%%n!"=="%%e" Set Found=true
    )
    if Not defined Found (
        set "_array=!_array!!_spc!"%%e""
        set "_spc= "
    )
)
::Displays actual output
echo %_array%
::Displays DESIRED output
echo "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
pause

Sample output:
>  SO_51147577.cmd
"A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
"A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
Drücken Sie eine beliebige Taste . . .

