Reputation: 70
So I'm trying to make the value inputted to call one of these arrays, however the only method I know is value[0], value[1] however that apparently splits down the value. I normaly do LUA and am not yet used to jQuery.
$(function(){
// User Pets
var John = ['Dog', 'Alive'];
var Emily = ['Cat', 'Alive'];
var Frank = ['Fish', 'Dead'];
var Greg = ['Dog', 'Alive'];
var Hannah = ['Camel', 'Dead'];
$('button').on('click', function() {
var value = $('#name').val()
console.log(value[0], value[1])
}); // Button
}); // Function
Upvotes: 0
Views: 35
Reputation: 144669
You can use an object:
var people = {
John: ['Dog', 'Alive'],
Emily: ['Cat', 'Alive'],
Frank: ['Fish', 'Dead'],
Greg: ['Dog', 'Alive'],
Hannah: ['Camel', 'Dead']
}
$('button').on('click', function() {
var value = $('#name').val();
var person = people[value];
if (!person) return console.log('User not found!');
console.log(person[0], person[1]);
});
Upvotes: 1