Yusnee Yusnee - 1 year ago 74
Javascript Question

add state on country array dynamically in js

var countries = ['India', 'China', 'Malaysia'];

var states = ['Penang', 'Johor', 'KL']; // for Malaysia

How can I add the states on related country array? Is that mean country array become 2 dimensional?

Answer Source

You could use an object to describe what a country is, instead of a name:

const countries = [{...}, {...}, {
    name: 'Malaysia',
    states: ['Penang', 'Johor', 'KL']
}, {...}];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download