0

I have this language array:

var messages = {
adult1:'Adult',
adult2:'Adults'
}

and this function

//id = 'adult';
//v = 2;

function changer(id,v){
var label = '';
label = eval(id+v);
console.log(messages.label);
//I want to see 'Adults' label
}

but the result is ReferenceError: adult2 is not defined

How can I concate both variables and create a new one that will print the variable from messages array

Thank you in advance

Europeuser
  • 934
  • 1
  • 9
  • 32

0 Answers0