this is my attempt

var test=["a","b","c"];
var var0="a";
for(var i=0; i<1; i++) {
    test.splice(test.indexOf(test[window["var"+i.toString()]]),1);
}
alert(test);

it alerts "a,b" but I want it to alert "b,c"

ref:http://stackoverflow.com/questions/5613834/convert-string-to-variable-name-in-javascript

Recommended Answers

All 2 Replies

Member Avatar for diafol

So what are you trying to do? Remove an item from an array and display the resulting array as a string?

var test = ["a","b","c"];
var var0 = 'a';

var index = test.indexOf(var0);

if (index > -1) {
    test.splice(index, 1);
    alert(test.toString());
}else{
    alert(var0 + ' not in array');
}

Imagine there are more than one var but they are named like var0, var1, var2, [..]
and I want to iterate through them, i was just use a smalle scale simplified example
I was close but I found the bug in line 4, within indexOf
This is what I was looking for

var test=["a","b","c"];
var var0="a";
for(var i=0; i<1; i++) {
    test.splice(test.indexOf(window["var"+i.toString()]),1);
}
alert(test);

Thanks for your reply
my next question about this here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.