Skip to main content
Helpful?

States

Import​

const states = require("country-cities").states;

Get all states​

const allStates = states.all();

console.log(allStates)

The result will be:

[
{
countryCode: "US",
isoCode: "VA",
latitude: "37.43157340",
longitude: "-78.65689420",
name: "Virginia"
},
{
countryCode: "US",
isoCode: "IL",
latitude: "40.63312490",
longitude: "-89.39852830",
name: "Illinois"
},
...
]

Get States by Country​

const usStates = states.getByCountry("US");

console.log(usStates)

The result will be:

[
{
countryCode: "US",
isoCode: "VA",
latitude: "37.43157340",
longitude: "-78.65689420",
name: "Virginia"
},
{
countryCode: "US",
isoCode: "IL",
latitude: "40.63312490",
longitude: "-89.39852830",
name: "Illinois"
},
...
]

Get States by Code​

const vaState = states.getByCode("VA", "US");

console.log(vaState)
Important: The country code should be entered second parameter

The result will be:

{
countryCode: "US",
isoCode: "VA",
latitude: "37.43157340",
longitude: "-78.65689420",
name: "Virginia"
}
Helpful?