I have an object with properties and sub-properties which I need to locate to find if they contain a certain value.
Here is a sample of my data object:
var data = [
{
value: 'Orlando International Airport (MCO)',
data: {
category: 'Airport',
address: '1 Jeff Fuqua Blvd., Orlando, FL',
airport: 'MCO',
location: 'Orlando'
}
},
{
value: 'Orlando Sanford International Airport (SFB)',
data: {
category: 'Airport',
address: '1200 Red Cleveland Blvd., Sanford, FL',
airport: 'SFB',
location: 'Orlando'
}
},
{
value: 'Port Canaveral Cruise Terminal',
data: {
category: 'Cruise Terminal',
address: 'Port Canaveral, FL',
airport: '',
location: 'Port Canaveral'
}
},
{
value: 'Baymont Inn & Suites Florida Mall/Orlando',
data: {
category: 'Hotel',
address: '8820 S Orange Blossom Trail, Orlando, FL',
airport: '',
location: 'Orlando'
}
},
The problem: I need to have a function that returns true if
location1 == 'Port Canaveral' && location2 == 'Orlando'
and false if
(location1 == 'Orlando' && location2 == 'Orlando') || (location1 == 'Port Canaveral' && location2 == 'Port Canaveral')
But I only know the "value" properties which should determine the corresponding locations. I hope someone who is really good at using JavaScript objects can help me here.
Update 1: In short, I need a function that is similar to this:
function locations_different(string1, string2) {
i1 = data.value.indexOf(string1);
location1 = data[i1].data.location;
i2 = data.value.indexOf(string2);
location2 = data[i2].data.location;
return ((location1 == 'Port Canaveral' && location2 == 'Orlando') && !((location1 == 'Orlando' && location2 == 'Orlando') || (location1 == 'Port Canaveral' && location2 == 'Port Canaveral')));
}
Update 2: Here's a non-working jsfiddle: http://jsfiddle.net/p1n20tzk/
Update 3: Here's a working one (Thanks to @james-k for starting it out) http://jsfiddle.net/edj0qvu0/
location1orlocation2in your objects.location1andlocation2are the arguments needed to be passed in the function.arg1.data.location == 'Port Canaveral' && arg2.data.location == 'Orlando'?arg1andarg2aren't objects, they are strings.