Skip to Content
๐ŸŽฒ Welcome to RandBox - Powerful JavaScript Random Data Generation Library! Learn More

state

// usage randBox.state() randBox.state({ full: true }) randBox.state({ territories: true }) randBox.state({ armed_forces: true }) randBox.state({ us_states_and_dc: false }) randBox.state({ country: 'us' })

Return a random state.

randBox.state(); => 'AK'

By default, returns only the 2 letter abbreviation for state.

Optionally specify that it ought to return a full state name.

randBox.state({ full: true }); => 'Florida'

Optionally add U.S. Territories (โ€˜American Samoaโ€™, โ€˜Federated States of Micronesiaโ€™, โ€˜Guamโ€™, โ€˜Marshall Islandsโ€™, โ€˜Northern Mariana Islandsโ€™, โ€˜Puerto Ricoโ€™, โ€˜Virgin Islands, U.S.โ€™) to the mix of randomly selected items:

randBox.state({ territories: true, full: true }) => 'Guam'

Optionally add Armed Forces to the list as well:

randBox.state({ armed_forces: true, full: true }) => 'Armed Forces Pacific'

For all U.S. states, territories, and armed forces, specify all of them:

randBox.state({ armed_forces: true, territories: true }) => 'NY'

For just territories or armed forces, specify that it ought not return U.S. states:

randBox.state({ territories: true, us_states_and_dc: false }) => 'PR'

Optionally specify a country (US specific options are ignored if country is specified and different from 'us'):

randBox.state({ country: 'it', full: true }) => 'Toscana'
Last updated on: