I have an array. Suppose the array is:
var group10 = ['as', '323fsd', 'asdasd', '43ssdf'];
I am passing the array into a function along with an array element so as to remove it from the array. If it removes, it will return true, otherwise, not.
function removeElem(element, array){
var index = array.indexOf(element);
if (index > -1) {
array.splice(index, 1);
return true;
}
}
The tricky part is, I'm getting numeric variables dynamically from another function and it's returning either 1 or 2 or .......... 10
If it returns 1, then I want to deal with group1
. If it returns 2, I want to deal with group2
.
Since the name group
is constant, I'm concatenating it with the variable it's returning and passing the whole into the function. But, unfortunately, a string is getting passed.
var arr = 'group'+10;
if( removeElem('323fsd', arr)) {
console.log(group10);
} else {
console.log('fail');
}
So, how is it possible to dynamically concatenating and passing the array as a whole into the function?