2
Contributors
2
Replies
15
Views
3 Years
Discussion Span
Last Post by nouth
0

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');
}

Edited by diafol

0

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

Edited by nouth

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.