Hello,
lets say the JSON is coded as possible:
var example = {
'95':
[ { cityId: 78, cityName: 'Kuala Kangsar' },
{ cityId: 94, cityName: 'Tanjung Malim' },
{ cityId: 1, cityName: 'Singapore' },
{ cityId: 9, cityName: 'Ipoh' },
{ cityId: 83, cityName: 'Taiping' } ],
'103':
[ { cityId: 11, cityName: 'Baling' },
{ cityId: 10, cityName: 'Alor Setar' },
{ cityId: 52, cityName: 'Jitra' },
{ cityId: 31, cityName: 'Butterworth' },
{ cityId: 12, cityName: 'Changlun' },
{ cityId: 33, cityName: 'Penang' } ] }
};
I've coded this as an object, because your example is using strings not
numerics, it could also be:
var example = [95:[ { cityId: 78, cityName: 'Kuala Kangsar' },
{ cityId: 94, cityName: 'Tanjung Malim' },
{ cityId: 1, cityName: 'Singapore' },
{ cityId: 9, cityName: 'Ipoh' },
{ cityId: 83, cityName: 'Taiping' } ],
103: [ { cityId: 11, cityName: 'Baling' },
{ cityId: 10, cityName: 'Alor Setar' },
{ cityId: 52, cityName: 'Jitra' },
{ cityId: 31, cityName: 'Butterworth' },
{ cityId: 12, cityName: 'Changlun' },
{ cityId: 33, cityName: 'Penang' } ] } ];
The test is the same:
var match;
if ( (match = example[95]) != undefined ) {
// Do something match points to the object referenced by 95.
}
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.