问:
How to get list of all timezones in javascript
I am developing an application with react/redux, and I started using library react-intl for formatting messages and dates.

I have already been able to show in a <FormattedDate> tag what timezone it's using.

I would like to have in a select all the possible timezones existing, so when the user picks one timezone, the <FormattedDate> changes to that format automatically.

I don't find how to list all posible timezones with react-intl.

I have also searched in google, and I did not find any built-in javascript function that does that.

Is it that way? How can I obtain that list?

Note: Don't think its the same question, since I don't want to use external libraries, if possible, if its the only solution then I will have to handle that way... :/

答:
I have updated the timezone list in the parent and child.

```var rows = [
{
  id: 1,
  continent: 'Asia',
  newRow: [
    {id: 1, country: 'Dubai', tz: 'Asia/Dubai'},
    {id: 2, country: 'Kabul', tz: 'Asia/Kabul'},
    {id: 3, country: 'Yerevan', tz: 'Asia/Yerevan'},
    {id: 4, country: 'Baku', tz: 'Asia/Baku'},
    {id: 5, country: 'Dhaka', tz: 'Asia/Dhaka'},
    {id: 6, country: 'Brunei', tz: 'Asia/Brunei'},
    {id: 7, country: 'Thimphu', tz: 'Asia/Thimphu'},
    {id: 8, country: 'Shanghai', tz: 'Asia/Shanghai'},
    {id: 9, country: 'Urumqi', tz: 'Asia/Urumqi'},
    {id: 10, country: 'Nicosia', tz: 'Asia/Nicosia'},
    {id: 11, country: 'Famagusta', tz: 'Asia/Famagusta'},
    {id: 12, country: 'Tbilisi', tz: 'Asia/Tbilisi'},
    {id: 13, country: 'Hong_Kong', tz: 'Asia/Hong_Kong'},
    {id: 14, country: 'Jakarta', tz: 'Asia/Jakarta'},
    {id: 15, country: 'Pontianak', tz: 'Asia/Pontianak'},
    {id: 16, country: 'Makassar', tz: 'Asia/Makassar'},
    {id: 17, country: 'Jayapura', tz: 'Asia/Jayapura'},
    {id: 18, country: 'Jerusalem', tz: 'Asia/Jerusalem'},
    {id: 19, country: 'Kolkata', tz: 'Asia/Kolkata'},
    {id: 20, country: 'Baghdad', tz: 'Asia/Baghdad'},
    {id: 21, country: 'Tehran', tz: 'Asia/Tehran'},
    {id: 22, country: 'Amman', tz: 'Asia/Amman'},
    {id: 23, country: 'Tokyo', tz: 'Asia/Tokyo'},
    {id: 24, country: 'Bishkek', tz: 'Asia/Bishkek'},
    {id: 25, country: 'Pyongyang', tz: 'Asia/Pyongyang'},
    {id: 26, country: 'Seoul', tz: 'Asia/Seoul'},
    {id: 27, country: 'Almaty', tz: 'Asia/Almaty'},
    {id: 28, country: 'Qyzylorda', tz: 'Asia/Qyzylorda'},
    {id: 29, country: 'Qostanay', tz: 'Asia/Qostanay'},
    {id: 30, country: 'Aqtobe', tz: 'Asia/Aqtobe'},
    {id: 31, country: 'Aqtau', tz: 'Asia/Aqtau'},
    {id: 32, country: 'Atyrau', tz: 'Asia/Atyrau'},
    {id: 33, country: 'Oral', tz: 'Asia/Oral'},
    {id: 34, country: 'Beirut', tz: 'Asia/Beirut'},
    {id: 35, country: 'Colombo', tz: 'Asia/Colombo'},
    {id: 36, country: 'Yangon', tz: 'Asia/Yangon'},
    {id: 37, country: 'Ulaanbaatar', tz: 'Asia/Ulaanbaatar'},
    {id: 38, country: 'Hovd', tz: 'Asia/Hovd'},
    {id: 39, country: 'Choibalsan', tz: 'Asia/Choibalsan'},
    {id: 40, country: 'Macau', tz: 'Asia/Macau'},
    {id: 41, country: 'Kuala_Lumpur', tz: 'Asia/Kuala_Lumpur'},
    {id: 42, country: 'Kuching', tz: 'Asia/Kuching'},
    {id: 43, country: 'Karachi', tz: 'Asia/Karachi'},
    {id: 44, country: 'Gaza', tz: 'Asia/Gaza'},
    {id: 45, country: 'Hebron', tz: 'Asia/Hebron'},
    {id: 46, country: 'Kathmandu', tz: 'Asia/Kathmandu'},
    {id: 47, country: 'Yekaterinburg', tz: 'Asia/Yekaterinburg'},
    {id: 48, country: 'Qatar', tz: 'Asia/Qatar'},
    {id: 49, country: 'Omsk', tz: 'Asia/Omsk'},
    {id: 50, country: 'Novosibirsk', tz: 'Asia/Novosibirsk'},
    {id: 51, country: 'Barnaul', tz: 'Asia/Barnaul'},
    {id: 52, country: 'Tomsk', tz: 'Asia/Tomsk'},
    {id: 53, country: 'Novokuznetsk', tz: 'Asia/Novokuznetsk'},
    {id: 54, country: 'Krasnoyarsk', tz: 'Asia/Krasnoyarsk'},
    {id: 55, country: 'Irkutsk', tz: 'Asia/Irkutsk'},
    {id: 56, country: 'Chita', tz: 'Asia/Chita'},
    {id: 57, country: 'Yakutsk', tz: 'Asia/Yakutsk'},
    {id: 58, country: 'Khandyga', tz: 'Asia/Khandyga'},
    {id: 59, country: 'Vladivostok', tz: 'Asia/Vladivostok'},
    {id: 60, country: 'Ust-Nera', tz: 'Asia/Ust-Nera'},
    {id: 61, country: 'Singapore', tz: 'Asia/Singapore'},
    {id: 62, country: 'Magadan', tz: 'Asia/Magadan'},
    {id: 63, country: 'Sakhalin', tz: 'Asia/Sakhalin'},
    {id: 64, country: 'Srednekolymsk', tz: 'Asia/Srednekolymsk'},
    {id: 65, country: 'Kamchatka', tz: 'Asia/Kamchatka'},
    {id: 66, country: 'Anadyr', tz: 'Asia/Anadyr'},
    {id: 67, country: 'Bangkok', tz: 'Asia/Bangkok'},
    {id: 68, country: 'Dushanbe', tz: 'Asia/Dushanbe'},
    {id: 69, country: 'Taipei', tz: 'Asia/Taipei'},
    {id: 70, country: 'Dili', tz: 'Asia/Dili'},
    {id: 71, country: 'Ashgabat', tz: 'Asia/Ashgabat'},
    {id: 72, country: 'Damascus', tz: 'Asia/Damascus'},
    {id: 73, country: 'Riyadh', tz: 'Asia/Riyadh'},
    {id: 74, country: 'Samarkand', tz: 'Asia/Samarkand'},
    {id: 75, country: 'Tashkent', tz: 'Asia/Tashkent'},
    {id: 76, country: 'Ho_Chi_Minh', tz: 'Asia/Ho_Chi_Minh'},
  ],
},
{
  id: 2,
  continent: 'Europe',
  newRow: [
    {id: 1, country: 'Andorra', tz: 'Europe/Andorra'},
    {id: 2, country: 'Tirane', tz: 'Europe/Tirane'},
    {id: 3, country: 'Vienna', tz: 'Europe/Vienna'},
    {id: 4, country: 'Brussels', tz: 'Europe/Brussels'},
    {id: 5, country: 'Sofia', tz: 'Europe/Sofia'},
    {id: 6, country: 'Minsk', tz: 'Europe/Minsk'},
    {id: 7, country: 'Zurich', tz: 'Europe/Zurich'},
    {id: 8, country: 'Prague', tz: 'Europe/Prague'},
    {id: 9, country: 'Berlin', tz: 'Europe/Berlin'},
    {id: 10, country: 'Copenhagen', tz: 'Europe/Copenhagen'},
    {id: 11, country: 'Tallinn', tz: 'Europe/Tallinn'},
    {id: 12, country: 'Madrid', tz: 'Europe/Madrid'},
    {id: 13, country: 'Helsinki', tz: 'Europe/Helsinki'},
    {id: 14, country: 'Paris', tz: 'Europe/Paris'},
    {id: 15, country: 'London', tz: 'Europe/London'},
    {id: 16, country: 'Gibraltar', tz: 'Europe/Gibraltar'},
    {id: 17, country: 'Athens', tz: 'Europe/Athens'},
    {id: 18, country: 'Budapest', tz: 'Europe/Budapest'},
    {id: 19, country: 'Dublin', tz: 'Europe/Dublin'},
    {id: 20, country: 'Rome', tz: 'Europe/Rome'},
    {id: 21, country: 'Vilnius', tz: 'Europe/Vilnius'},
    {id: 22, country: 'Luxembourg', tz: 'Europe/Luxembourg'},
    {id: 23, country: 'Riga', tz: 'Europe/Riga'},
    {id: 24, country: 'Monaco', tz: 'Europe/Monaco'},
    {id: 25, country: 'Chisinau', tz: 'Europe/Chisinau'},
    {id: 26, country: 'Malta', tz: 'Europe/Malta'},
    {id: 27, country: 'Amsterdam', tz: 'Europe/Amsterdam'},
    {id: 28, country: 'Oslo', tz: 'Europe/Oslo'},
    {id: 29, country: 'Warsaw', tz: 'Europe/Warsaw'},
    {id: 30, country: 'Warsaw', tz: 'Europe/Warsaw'},
    {id: 31, country: 'Lisbon', tz: 'Europe/Lisbon'},
    {id: 32, country: 'Bucharest', tz: 'Europe/Bucharest'},
    {id: 33, country: 'Belgrade', tz: 'Europe/Belgrade'},
    {id: 34, country: 'Kaliningrad', tz: 'Europe/Kaliningrad'},
    {id: 35, country: 'Moscow', tz: 'Europe/Moscow'},
    {id: 36, country: 'Simferopol', tz: 'Europe/Simferopol'},
    {id: 37, country: 'Kirov', tz: 'Europe/Kirov'},
    {id: 38, country: 'Astrakhan', tz: 'Europe/Astrakhan'},
    {id: 39, country: 'Volgograd', tz: 'Europe/Volgograd'},
    {id: 40, country: 'Saratov', tz: 'Europe/Saratov'},
    {id: 41, country: 'Ulyanovsk', tz: 'Europe/Ulyanovsk'},
    {id: 42, country: 'Samara', tz: 'Europe/Samara'},
    {id: 43, country: 'Stockholm', tz: 'Europe/Stockholm'},
    {id: 44, country: 'Istanbul', tz: 'Europe/Istanbul'},
    {id: 45, country: 'Kiev', tz: 'Europe/Kiev'},
    {id: 46, country: 'Uzhgorod', tz: 'Europe/Uzhgorod'},
    {id: 47, country: 'Zaporozhye', tz: 'Europe/Zaporozhye'},
  ],
},
{
  id: 3,
  continent: 'Antarctica',
  newRow: [
    {id: 1, country: 'Casey', tz: 'Antarctica/Casey'},
    {id: 2, country: 'Davis', tz: 'Antarctica/Davis'},
    {id: 3, country: 'DumontDUrville', tz: 'Antarctica/DumontDUrville'},
    {id: 4, country: 'Mawson', tz: 'Antarctica/Mawson'},
    {id: 5, country: 'Palmer', tz: 'Antarctica/Palmer'},
    {id: 6, country: 'Rothera', tz: 'Antarctica/Rothera'},
    {id: 7, country: 'Syowa', tz: 'Antarctica/Syowa'},
    {id: 8, country: 'Troll', tz: 'Antarctica/Troll'},
    {id: 9, country: 'Vostok', tz: 'Antarctica/Vostok'},
    {id: 10, country: 'Macquarie', tz: 'Antarctica/Macquarie'},
  ],
},
{
  id: 4,
  continent: 'America',
  newRow: [
    {id: 1, country: 'Buenos_Aires', tz: 'America/Argentina/Buenos_Aires'},
    {id: 2, country: 'Cordoba', tz: 'America/Argentina/Cordoba'},
    {id: 3, country: 'Salta', tz: 'America/Argentina/Salta'},
    {id: 4, country: 'Jujuy', tz: 'America/Argentina/Jujuy'},
    {id: 5, country: 'Tucuman', tz: 'America/Argentina/Tucuman'},
    {id: 6, country: 'Catamarca', tz: 'America/Argentina/Catamarca'},
    {id: 7, country: 'La_Rioja', tz: 'America/Argentina/La_Rioja'},
    {id: 8, country: 'San_Juan', tz: 'America/Argentina/San_Juan'},
    {id: 9, country: 'Mendoza', tz: 'America/Argentina/Mendoza'},
    {id: 10, country: 'San_Luis', tz: 'America/Argentina/San_Luis'},
    {id: 11, country: 'Rio_Gallegos', tz: 'America/Argentina/Rio_Gallegos'},
    {id: 12, country: 'Ushuaia', tz: 'America/Argentina/Ushuaia'},
    {id: 13, country: 'Barbados', tz: 'America/Barbados'},
    {id: 14, country: 'La_Paz', tz: 'America/La_Paz'},
    {id: 15, country: 'Belem', tz: 'America/Belem'},
    {id: 16, country: 'Fortaleza', tz: 'America/Fortaleza'},
    {id: 17, country: 'Recife', tz: 'America/Recife'},
    {id: 18, country: 'Araguaina', tz: 'America/Araguaina'},
    {id: 19, country: 'Maceio', tz: 'America/Maceio'},
    {id: 20, country: 'Bahia', tz: 'America/Bahia'},
    {id: 21, country: 'Sao_Paulo', tz: 'America/Sao_Paulo'},
    {id: 22, country: 'Campo_Grande', tz: 'America/Campo_Grande'},
    {id: 23, country: 'Cuiaba', tz: 'America/Cuiaba'},
    {id: 24, country: 'Porto_Velho', tz: 'America/Porto_Velho'},
    {id: 25, country: 'Boa_Vista', tz: 'America/Boa_Vista'},
    {id: 26, country: 'Manaus', tz: 'America/Manaus'},
    {id: 27, country: 'Eirunepe', tz: 'America/Eirunepe'},
    {id: 28, country: 'Rio_Branco', tz: 'America/Rio_Branco'},
    {id: 29, country: 'Nassau', tz: 'America/Nassau'},
    {id: 30, country: 'Belize', tz: 'America/Belize'},
    {id: 31, country: 'St_Johns', tz: 'America/St_Johns'},
    {id: 32, country: 'Halifax', tz: 'America/Halifax'},
    {id: 33, country: 'Glace_Bay', tz: 'America/Glace_Bay'},
    {id: 34, country: 'Moncton', tz: 'America/Moncton'},
    {id: 35, country: 'Goose_Bay', tz: 'America/Goose_Bay'},
    {id: 36, country: 'Blanc-Sablon', tz: 'America/Blanc-Sablon'},
    {id: 37, country: 'Toronto', tz: 'America/Toronto'},
    {id: 38, country: 'Nipigon', tz: 'America/Nipigon'},
    {id: 39, country: 'Thunder_Bay', tz: 'America/Thunder_Bay'},
    {id: 40, country: 'Iqaluit', tz: 'America/Iqaluit'},
    {id: 41, country: 'Pangnirtung', tz: 'America/Pangnirtung'},
    {id: 42, country: 'Atikokan', tz: 'America/Atikokan'},
    {id: 43, country: 'Winnipeg', tz: 'America/Winnipeg'},
    {id: 44, country: 'Rainy_River', tz: 'America/Rainy_River'},
    {id: 45, country: 'Resolute', tz: 'America/Resolute'},
    {id: 46, country: 'Rankin_Inlet', tz: 'America/Rankin_Inlet'},
    {id: 47, country: 'Regina', tz: 'America/Regina'},
    {id: 48, country: 'Swift_Current', tz: 'America/Swift_Current'},
    {id: 49, country: 'Edmonton', tz: 'America/Edmonton'},
    {id: 50, country: 'Cambridge_Bay', tz: 'America/Cambridge_Bay'},
    {id: 51, country: 'Yellowknife', tz: 'America/Yellowknife'},
    {id: 52, country: 'Inuvik', tz: 'America/Inuvik'},
    {id: 53, country: 'Creston', tz: 'America/Creston'},
    {id: 54, country: 'Dawson_Creek', tz: 'America/Dawson_Creek'},
    {id: 55, country: 'Fort_Nelson', tz: 'America/Fort_Nelson'},
    {id: 56, country: 'Vancouver', tz: 'America/Vancouver'},
    {id: 57, country: 'Whitehorse', tz: 'America/Whitehorse'},
    {id: 58, country: 'Dawson', tz: 'America/Dawson'},
    {id: 59, country: 'Santiago', tz: 'America/Santiago'},
    {id: 60, country: 'Punta_Arenas', tz: 'America/Punta_Arenas'},
    {id: 61, country: 'Bogota', tz: 'America/Bogota'},
    {id: 62, country: 'Costa_Rica', tz: 'America/Costa_Rica'},
    {id: 63, country: 'Havana', tz: 'America/Havana'},
    {id: 64, country: 'Curacao', tz: 'America/Curacao'},
    {id: 65, country: 'Santo_Domingo', tz: 'America/Santo_Domingo'},
    {id: 66, country: 'Guayaquil', tz: 'America/Guayaquil'},
    {id: 67, country: 'Cayenne', tz: 'America/Cayenne'},
    {id: 68, country: 'Godthab', tz: 'America/Godthab'},
    {id: 69, country: 'Danmarkshavn', tz: 'America/Danmarkshavn'},
    {id: 70, country: 'Scoresbysund', tz: 'America/Scoresbysund'},
    {id: 71, country: 'Cayenne', tz: 'America/Cayenne'},
    {id: 72, country: 'Godthab', tz: 'America/Godthab'},
    {id: 73, country: 'Danmarkshavn', tz: 'America/Danmarkshavn'},
    {id: 74, country: 'Scoresbysund', tz: 'America/Scoresbysund'},
    {id: 75, country: 'Thule', tz: 'America/Thule'},
    {id: 76, country: 'Guatemala', tz: 'America/Guatemala'},
    {id: 77, country: 'Guyana', tz: 'America/Guyana'},
    {id: 78, country: 'Tegucigalpa', tz: 'America/Tegucigalpa'},
    {id: 79, country: 'Port-au-Prince', tz: 'America/Port-au-Prince'},
    {id: 80, country: 'Jamaica', tz: 'America/Jamaica'},
    {id: 81, country: 'Martinique', tz: 'America/Martinique'},
    {id: 82, country: 'Mexico_City', tz: 'America/Mexico_City'},
    {id: 83, country: 'Cancun', tz: 'America/Cancun'},
    {id: 84, country: 'Merida', tz: 'America/Merida'},
    {id: 85, country: 'Monterrey', tz: 'America/Monterrey'},
    {id: 86, country: 'Matamoros', tz: 'America/Matamoros'},
    {id: 87, country: 'Caracas', tz: 'America/Caracas'},
    {id: 88, country: 'Mazatlan', tz: 'America/Mazatlan'},
    {id: 89, country: 'Chihuahua', tz: 'America/Chihuahua'},
    {id: 90, country: 'Ojinaga', tz: 'America/Ojinaga'},
    {id: 91, country: 'Hermosillo', tz: 'America/Hermosillo'},
    {id: 92, country: 'Tijuana', tz: 'America/Tijuana'},
    {id: 93, country: 'Bahia_Banderas', tz: 'America/Bahia_Banderas'},
    {id: 94, country: 'Managua', tz: 'America/Managua'},
    {id: 95, country: 'Panama', tz: 'America/Panama'},
    {id: 96, country: 'Lima', tz: 'America/Lima'},
    {id: 97, country: 'Miquelon', tz: 'America/Miquelon'},
    {id: 98, country: 'Puerto_Rico', tz: 'America/Puerto_Rico'},
    {id: 99, country: 'El_Salvador', tz: 'America/El_Salvador'},
    {id: 100, country: 'Grand_Turk', tz: 'America/Grand_Turk'},
    {id: 101, country: 'Paramaribo', tz: 'America/Paramaribo'},
    {id: 102, country: 'Asuncion', tz: 'America/Asuncion'},
    {id: 103, country: 'Port_of_Spain', tz: 'America/Port_of_Spain'},
    {id: 104, country: 'New_York', tz: 'America/New_York'},
    {id: 105, country: 'Detroit', tz: 'America/Detroit'},
    {id: 106, country: 'Louisville', tz: 'America/Kentucky/Louisville'},
    {id: 107, country: 'Monticello', tz: 'America/Kentucky/Monticello'},
    {id: 108, country: 'Indianapolis', tz: 'America/Indiana/Indianapolis'},
    {id: 109, country: 'Vincennes', tz: 'America/Indiana/Vincennes'},
    {id: 110, country: 'Winamac', tz: 'America/Indiana/Winamac'},
    {id: 111, country: 'Marengo', tz: 'America/Indiana/Marengo'},
    {id: 112, country: 'Petersburg', tz: 'America/Indiana/Petersburg'},
    {id: 113, country: 'Vevay', tz: 'America/Indiana/Vevay'},
    {id: 114, country: 'Tell_City', tz: 'America/Indiana/Tell_City'},
    {id: 115, country: 'Knox', tz: 'America/Indiana/Knox'},
    {id: 116, country: 'Chicago', tz: 'America/Chicago'},
    {id: 117, country: 'Menominee', tz: 'America/Menominee'},
    {id: 118, country: 'Denver', tz: 'America/Denver'},
    {id: 119, country: 'Boise', tz: 'America/Boise'},
    {id: 120, country: 'Phoenix', tz: 'America/Phoenix'},
    {id: 121, country: 'Center', tz: 'America/North_Dakota/Center'},
    {id: 122, country: 'New_Salem', tz: 'America/North_Dakota/New_Salem'},
    {id: 123, country: 'Beulah', tz: 'America/North_Dakota/Beulah'},
    {id: 124, country: 'Los_Angeles', tz: 'America/Los_Angeles'},
    {id: 125, country: 'Anchorage', tz: 'America/Anchorage'},
    {id: 126, country: 'Juneau', tz: 'America/Juneau'},
    {id: 127, country: 'Sitka', tz: 'America/Sitka'},
    {id: 128, country: 'Metlakatla', tz: 'America/Metlakatla'},
    {id: 129, country: 'Yakutat', tz: 'America/Yakutat'},
    {id: 130, country: 'Nome', tz: 'America/Nome'},
    {id: 131, country: 'Adak', tz: 'America/Adak'},
    {id: 132, country: 'Montevideo', tz: 'America/Montevideo'},
  ],
},
{
  id: 5,
  continent: 'Pacific',
  newRow: [
    {id: 1, country: 'Pago_Pago', tz: 'Pacific/Pago_Pago'},
    {id: 2, country: 'Rarotonga', tz: 'Pacific/Rarotonga'},
    {id: 3, country: 'Easter', tz: 'Pacific/Easter'},
    {id: 4, country: 'Galapagos', tz: 'Pacific/Galapagos'},
    {id: 5, country: 'Fiji', tz: 'Pacific/Fiji'},
    {id: 6, country: 'Chuuk', tz: 'Pacific/Chuuk'},
    {id: 7, country: 'Pohnpei', tz: 'Pacific/Pohnpei'},
    {id: 8, country: 'Kosrae', tz: 'Pacific/Kosrae'},
    {id: 9, country: 'Guam', tz: 'Pacific/Guam'},
    {id: 10, country: 'Majuro', tz: 'Pacific/Majuro'},
    {id: 11, country: 'Kwajalein', tz: 'Pacific/Kwajalein'},
    {id: 12, country: 'Tarawa', tz: 'Pacific/Tarawa'},
    {id: 13, country: 'Enderbury', tz: 'Pacific/Enderbury'},
    {id: 14, country: 'Kiritimati', tz: 'Pacific/Kiritimati'},
    {id: 15, country: 'Noumea', tz: 'Pacific/Noumea'},
    {id: 16, country: 'Norfolk', tz: 'Pacific/Norfolk'},
    {id: 17, country: 'Nauru', tz: 'Pacific/Nauru'},
    {id: 18, country: 'Niue', tz: 'Pacific/Niue'},
    {id: 19, country: 'Auckland', tz: 'Pacific/Auckland'},
    {id: 20, country: 'Chatham', tz: 'Pacific/Chatham'},
    {id: 21, country: 'Tahiti', tz: 'Pacific/Tahiti'},
    {id: 22, country: 'Marquesas', tz: 'Pacific/Marquesas'},
    {id: 23, country: 'Gambier', tz: 'Pacific/Gambier'},
    {id: 24, country: 'Port_Moresby', tz: 'Pacific/Port_Moresby'},
    {id: 25, country: 'Bougainville', tz: 'Pacific/Bougainville'},
    {id: 26, country: 'Pitcairn', tz: 'Pacific/Pitcairn'},
    {id: 27, country: 'Palau', tz: 'Pacific/Palau'},
    {id: 28, country: 'Guadalcanal', tz: 'Pacific/Guadalcanal'},
    {id: 29, country: 'Fakaofo', tz: 'Pacific/Fakaofo'},
    {id: 30, country: 'Tongatapu', tz: 'Pacific/Tongatapu'},
    {id: 31, country: 'Funafuti', tz: 'Pacific/Funafuti'},
    {id: 32, country: 'Wake', tz: 'Pacific/Wake'},
    {id: 33, country: 'Honolulu', tz: 'Pacific/Honolulu'},
    {id: 34, country: 'Efate', tz: 'Pacific/Efate'},
    {id: 35, country: 'Wallis', tz: 'Pacific/Wallis'},
    {id: 36, country: 'Apia', tz: 'Pacific/Apia'},
  ],
},
{
  id: 6,
  continent: 'Australia',
  newRow: [
    {id: 1, country: 'Lord_Howe', tz: 'Australia/Lord_Howe'},
    {id: 2, country: 'Hobart', tz: 'Australia/Hobart'},
    {id: 3, country: 'Currie', tz: 'Australia/Currie'},
    {id: 4, country: 'Melbourne', tz: 'Australia/Melbourne'},
    {id: 5, country: 'Sydney', tz: 'Australia/Sydney'},
    {id: 6, country: 'Broken_Hill', tz: 'Australia/Broken_Hill'},
    {id: 7, country: 'Brisbane', tz: 'Australia/Brisbane'},
    {id: 8, country: 'Lindeman', tz: 'Australia/Lindeman'},
    {id: 9, country: 'Adelaide', tz: 'Australia/Adelaide'},
    {id: 10, country: 'Darwin', tz: 'Australia/Darwin'},
    {id: 11, country: 'Perth', tz: 'Australia/Perth'},
    {id: 12, country: 'Eucla', tz: 'Australia/Eucla'},
  ],
},
{
  id: 7,
  continent: 'Africa',
  newRow: [
    {id: 1, country: 'Abidjan', tz: 'Africa/Abidjan'},
    {id: 2, country: 'Algiers', tz: 'Africa/Algiers'},
    {id: 3, country: 'Cairo', tz: 'Africa/Cairo'},
    {id: 4, country: 'El_Aaiun', tz: 'Africa/El_Aaiun'},
    {id: 5, country: 'Ceuta', tz: 'Africa/Ceuta'},
    {id: 6, country: 'Accra', tz: 'Africa/Accra'},
    {id: 7, country: 'Bissau', tz: 'Africa/Bissau'},
    {id: 8, country: 'Nairobi', tz: 'Africa/Nairobi'},
    {id: 9, country: 'Monrovia', tz: 'Africa/Monrovia'},
    {id: 10, country: 'Tripoli', tz: 'Africa/Tripoli'},
    {id: 11, country: 'Casablanca', tz: 'Africa/Casablanca'},
    {id: 12, country: 'Maputo', tz: 'Africa/Maputo'},
    {id: 13, country: 'Windhoek', tz: 'Africa/Windhoek'},
    {id: 14, country: 'Lagos', tz: 'Africa/Lagos'},
    {id: 15, country: 'Khartoum', tz: 'Africa/Khartoum'},
    {id: 16, country: 'Juba', tz: 'Africa/Juba'},
    {id: 17, country: 'Sao_Tome', tz: 'Africa/Sao_Tome'},
    {id: 18, country: 'Ndjamena', tz: 'Africa/Ndjamena'},
    {id: 19, country: 'Tunis', tz: 'Africa/Tunis'},
    {id: 20, country: 'Johannesburg', tz: 'Africa/Johannesburg'},
  ],
},
{
  id: 8,
  continent: 'Atlantic',
  newRow: [
    {id: 1, country: 'Azores', tz: 'Atlantic/Azores'},
    {id: 2, country: 'Bermuda', tz: 'Atlantic/Bermuda'},
    {id: 3, country: 'Madeira', tz: 'Atlantic/Madeira'},
  ],
},
{
  id: 9,
  continent: 'Atlantic',
  newRow: [
    {id: 1, country: 'Cape_Verde', tz: 'Atlantic/Cape_Verde'},
    {id: 2, country: 'Canary', tz: 'Atlantic/Canary'},
    {id: 3, country: 'Stanley', tz: 'Atlantic/Stanley'},
    {id: 4, country: 'Faroe', tz: 'Atlantic/Faroe'},
    {id: 5, country: 'South_Georgia', tz: 'Atlantic/South_Georgia'},
    {id: 6, country: 'Reykjavik', tz: 'Atlantic/Reykjavik'},
  ],
},
{
  id: 10,
  continent: 'Indian',
  newRow: [
    {id: 1, country: 'Cocos', tz: 'Indian/Cocos'},
    {id: 2, country: 'Christmas', tz: 'Indian/Christmas'},
    {id: 3, country: 'Chagos', tz: 'Indian/Chagos'},
    {id: 4, country: 'Mauritius', tz: 'Indian/Mauritius'},
    {id: 5, country: 'Maldives', tz: 'Indian/Maldives'},
    {id: 6, country: 'Mahe', tz: 'Indian/Mahe'},
    {id: 7, country: 'Reunion', tz: 'Indian/Reunion'},
    {id: 8, country: 'Kerguelen', tz: 'Indian/Kerguelen'},
  ],
},
```

];

Body:
I have updated the timezone list in the parent and child.

var rows = [
{
  id: 1,
  continent: 'Asia',
  newRow: [
    {id: 1, country: 'Dubai', tz: 'Asia/Dubai'},
    {id: 2, country: 'Kabul', tz: 'Asia/Kabul'},
    {id: 3, country: 'Yerevan', tz: 'Asia/Yerevan'},
    {id: 4, country: 'Baku', tz: 'Asia/Baku'},
    {id: 5, country: 'Dhaka', tz: 'Asia/Dhaka'},
    {id: 6, country: 'Brunei', tz: 'Asia/Brunei'},
    {id: 7, country: 'Thimphu', tz: 'Asia/Thimphu'},
    {id: 8, country: 'Shanghai', tz: 'Asia/Shanghai'},
    {id: 9, country: 'Urumqi', tz: 'Asia/Urumqi'},
    {id: 10, country: 'Nicosia', tz: 'Asia/Nicosia'},
    {id: 11, country: 'Famagusta', tz: 'Asia/Famagusta'},
    {id: 12, country: 'Tbilisi', tz: 'Asia/Tbilisi'},
    {id: 13, country: 'Hong_Kong', tz: 'Asia/Hong_Kong'},
    {id: 14, country: 'Jakarta', tz: 'Asia/Jakarta'},
    {id: 15, country: 'Pontianak', tz: 'Asia/Pontianak'},
    {id: 16, country: 'Makassar', tz: 'Asia/Makassar'},
    {id: 17, country: 'Jayapura', tz: 'Asia/Jayapura'},
    {id: 18, country: 'Jerusalem', tz: 'Asia/Jerusalem'},
    {id: 19, country: 'Kolkata', tz: 'Asia/Kolkata'},
    {id: 20, country: 'Baghdad', tz: 'Asia/Baghdad'},
    {id: 21, country: 'Tehran', tz: 'Asia/Tehran'},
    {id: 22, country: 'Amman', tz: 'Asia/Amman'},
    {id: 23, country: 'Tokyo', tz: 'Asia/Tokyo'},
    {id: 24, country: 'Bishkek', tz: 'Asia/Bishkek'},
    {id: 25, country: 'Pyongyang', tz: 'Asia/Pyongyang'},
    {id: 26, country: 'Seoul', tz: 'Asia/Seoul'},
    {id: 27, country: 'Almaty', tz: 'Asia/Almaty'},
    {id: 28, country: 'Qyzylorda', tz: 'Asia/Qyzylorda'},
    {id: 29, country: 'Qostanay', tz: 'Asia/Qostanay'},
    {id: 30, country: 'Aqtobe', tz: 'Asia/Aqtobe'},
    {id: 31, country: 'Aqtau', tz: 'Asia/Aqtau'},
    {id: 32, country: 'Atyrau', tz: 'Asia/Atyrau'},
    {id: 33, country: 'Oral', tz: 'Asia/Oral'},
    {id: 34, country: 'Beirut', tz: 'Asia/Beirut'},
    {id: 35, country: 'Colombo', tz: 'Asia/Colombo'},
    {id: 36, country: 'Yangon', tz: 'Asia/Yangon'},
    {id: 37, country: 'Ulaanbaatar', tz: 'Asia/Ulaanbaatar'},
    {id: 38, country: 'Hovd', tz: 'Asia/Hovd'},
    {id: 39, country: 'Choibalsan', tz: 'Asia/Choibalsan'},
    {id: 40, country: 'Macau', tz: 'Asia/Macau'},
    {id: 41, country: 'Kuala_Lumpur', tz: 'Asia/Kuala_Lumpur'},
    {id: 42, country: 'Kuching', tz: 'Asia/Kuching'},
    {id: 43, country: 'Karachi', tz: 'Asia/Karachi'},
    {id: 44, country: 'Gaza', tz: 'Asia/Gaza'},
    {id: 45, country: 'Hebron', tz: 'Asia/Hebron'},
    {id: 46, country: 'Kathmandu', tz: 'Asia/Kathmandu'},
    {id: 47, country: 'Yekaterinburg', tz: 'Asia/Yekaterinburg'},
    {id: 48, country: 'Qatar', tz: 'Asia/Qatar'},
    {id: 49, country: 'Omsk', tz: 'Asia/Omsk'},
    {id: 50, country: 'Novosibirsk', tz: 'Asia/Novosibirsk'},
    {id: 51, country: 'Barnaul', tz: 'Asia/Barnaul'},
    {id: 52, country: 'Tomsk', tz: 'Asia/Tomsk'},
    {id: 53, country: 'Novokuznetsk', tz: 'Asia/Novokuznetsk'},
    {id: 54, country: 'Krasnoyarsk', tz: 'Asia/Krasnoyarsk'},
    {id: 55, country: 'Irkutsk', tz: 'Asia/Irkutsk'},
    {id: 56, country: 'Chita', tz: 'Asia/Chita'},
    {id: 57, country: 'Yakutsk', tz: 'Asia/Yakutsk'},
    {id: 58, country: 'Khandyga', tz: 'Asia/Khandyga'},
    {id: 59, country: 'Vladivostok', tz: 'Asia/Vladivostok'},
    {id: 60, country: 'Ust-Nera', tz: 'Asia/Ust-Nera'},
    {id: 61, country: 'Singapore', tz: 'Asia/Singapore'},
    {id: 62, country: 'Magadan', tz: 'Asia/Magadan'},
    {id: 63, country: 'Sakhalin', tz: 'Asia/Sakhalin'},
    {id: 64, country: 'Srednekolymsk', tz: 'Asia/Srednekolymsk'},
    {id: 65, country: 'Kamchatka', tz: 'Asia/Kamchatka'},
    {id: 66, country: 'Anadyr', tz: 'Asia/Anadyr'},
    {id: 67, country: 'Bangkok', tz: 'Asia/Bangkok'},
    {id: 68, country: 'Dushanbe', tz: 'Asia/Dushanbe'},
    {id: 69, country: 'Taipei', tz: 'Asia/Taipei'},
    {id: 70, country: 'Dili', tz: 'Asia/Dili'},
    {id: 71, country: 'Ashgabat', tz: 'Asia/Ashgabat'},
    {id: 72, country: 'Damascus', tz: 'Asia/Damascus'},
    {id: 73, country: 'Riyadh', tz: 'Asia/Riyadh'},
    {id: 74, country: 'Samarkand', tz: 'Asia/Samarkand'},
    {id: 75, country: 'Tashkent', tz: 'Asia/Tashkent'},
    {id: 76, country: 'Ho_Chi_Minh', tz: 'Asia/Ho_Chi_Minh'},
  ],
},
{
  id: 2,
  continent: 'Europe',
  newRow: [
    {id: 1, country: 'Andorra', tz: 'Europe/Andorra'},
    {id: 2, country: 'Tirane', tz: 'Europe/Tirane'},
    {id: 3, country: 'Vienna', tz: 'Europe/Vienna'},
    {id: 4, country: 'Brussels', tz: 'Europe/Brussels'},
    {id: 5, country: 'Sofia', tz: 'Europe/Sofia'},
    {id: 6, country: 'Minsk', tz: 'Europe/Minsk'},
    {id: 7, country: 'Zurich', tz: 'Europe/Zurich'},
    {id: 8, country: 'Prague', tz: 'Europe/Prague'},
    {id: 9, country: 'Berlin', tz: 'Europe/Berlin'},
    {id: 10, country: 'Copenhagen', tz: 'Europe/Copenhagen'},
    {id: 11, country: 'Tallinn', tz: 'Europe/Tallinn'},
    {id: 12, country: 'Madrid', tz: 'Europe/Madrid'},
    {id: 13, country: 'Helsinki', tz: 'Europe/Helsinki'},
    {id: 14, country: 'Paris', tz: 'Europe/Paris'},
    {id: 15, country: 'London', tz: 'Europe/London'},
    {id: 16, country: 'Gibraltar', tz: 'Europe/Gibraltar'},
    {id: 17, country: 'Athens', tz: 'Europe/Athens'},
    {id: 18, country: 'Budapest', tz: 'Europe/Budapest'},
    {id: 19, country: 'Dublin', tz: 'Europe/Dublin'},
    {id: 20, country: 'Rome', tz: 'Europe/Rome'},
    {id: 21, country: 'Vilnius', tz: 'Europe/Vilnius'},
    {id: 22, country: 'Luxembourg', tz: 'Europe/Luxembourg'},
    {id: 23, country: 'Riga', tz: 'Europe/Riga'},
    {id: 24, country: 'Monaco', tz: 'Europe/Monaco'},
    {id: 25, country: 'Chisinau', tz: 'Europe/Chisinau'},
    {id: 26, country: 'Malta', tz: 'Europe/Malta'},
    {id: 27, country: 'Amsterdam', tz: 'Europe/Amsterdam'},
    {id: 28, country: 'Oslo', tz: 'Europe/Oslo'},
    {id: 29, country: 'Warsaw', tz: 'Europe/Warsaw'},
    {id: 30, country: 'Warsaw', tz: 'Europe/Warsaw'},
    {id: 31, country: 'Lisbon', tz: 'Europe/Lisbon'},
    {id: 32, country: 'Bucharest', tz: 'Europe/Bucharest'},
    {id: 33, country: 'Belgrade', tz: 'Europe/Belgrade'},
    {id: 34, country: 'Kaliningrad', tz: 'Europe/Kaliningrad'},
    {id: 35, country: 'Moscow', tz: 'Europe/Moscow'},
    {id: 36, country: 'Simferopol', tz: 'Europe/Simferopol'},
    {id: 37, country: 'Kirov', tz: 'Europe/Kirov'},
    {id: 38, country: 'Astrakhan', tz: 'Europe/Astrakhan'},
    {id: 39, country: 'Volgograd', tz: 'Europe/Volgograd'},
    {id: 40, country: 'Saratov', tz: 'Europe/Saratov'},
    {id: 41, country: 'Ulyanovsk', tz: 'Europe/Ulyanovsk'},
    {id: 42, country: 'Samara', tz: 'Europe/Samara'},
    {id: 43, country: 'Stockholm', tz: 'Europe/Stockholm'},
    {id: 44, country: 'Istanbul', tz: 'Europe/Istanbul'},
    {id: 45, country: 'Kiev', tz: 'Europe/Kiev'},
    {id: 46, country: 'Uzhgorod', tz: 'Europe/Uzhgorod'},
    {id: 47, country: 'Zaporozhye', tz: 'Europe/Zaporozhye'},
  ],
},
{
  id: 3,
  continent: 'Antarctica',
  newRow: [
    {id: 1, country: 'Casey', tz: 'Antarctica/Casey'},
    {id: 2, country: 'Davis', tz: 'Antarctica/Davis'},
    {id: 3, country: 'DumontDUrville', tz: 'Antarctica/DumontDUrville'},
    {id: 4, country: 'Mawson', tz: 'Antarctica/Mawson'},
    {id: 5, country: 'Palmer', tz: 'Antarctica/Palmer'},
    {id: 6, country: 'Rothera', tz: 'Antarctica/Rothera'},
    {id: 7, country: 'Syowa', tz: 'Antarctica/Syowa'},
    {id: 8, country: 'Troll', tz: 'Antarctica/Troll'},
    {id: 9, country: 'Vostok', tz: 'Antarctica/Vostok'},
    {id: 10, country: 'Macquarie', tz: 'Antarctica/Macquarie'},
  ],
},
{
  id: 4,
  continent: 'America',
  newRow: [
    {id: 1, country: 'Buenos_Aires', tz: 'America/Argentina/Buenos_Aires'},
    {id: 2, country: 'Cordoba', tz: 'America/Argentina/Cordoba'},
    {id: 3, country: 'Salta', tz: 'America/Argentina/Salta'},
    {id: 4, country: 'Jujuy', tz: 'America/Argentina/Jujuy'},
    {id: 5, country: 'Tucuman', tz: 'America/Argentina/Tucuman'},
    {id: 6, country: 'Catamarca', tz: 'America/Argentina/Catamarca'},
    {id: 7, country: 'La_Rioja', tz: 'America/Argentina/La_Rioja'},
    {id: 8, country: 'San_Juan', tz: 'America/Argentina/San_Juan'},
    {id: 9, country: 'Mendoza', tz: 'America/Argentina/Mendoza'},
    {id: 10, country: 'San_Luis', tz: 'America/Argentina/San_Luis'},
    {id: 11, country: 'Rio_Gallegos', tz: 'America/Argentina/Rio_Gallegos'},
    {id: 12, country: 'Ushuaia', tz: 'America/Argentina/Ushuaia'},
    {id: 13, country: 'Barbados', tz: 'America/Barbados'},
    {id: 14, country: 'La_Paz', tz: 'America/La_Paz'},
    {id: 15, country: 'Belem', tz: 'America/Belem'},
    {id: 16, country: 'Fortaleza', tz: 'America/Fortaleza'},
    {id: 17, country: 'Recife', tz: 'America/Recife'},
    {id: 18, country: 'Araguaina', tz: 'America/Araguaina'},
    {id: 19, country: 'Maceio', tz: 'America/Maceio'},
    {id: 20, country: 'Bahia', tz: 'America/Bahia'},
    {id: 21, country: 'Sao_Paulo', tz: 'America/Sao_Paulo'},
    {id: 22, country: 'Campo_Grande', tz: 'America/Campo_Grande'},
    {id: 23, country: 'Cuiaba', tz: 'America/Cuiaba'},
    {id: 24, country: 'Porto_Velho', tz: 'America/Porto_Velho'},
    {id: 25, country: 'Boa_Vista', tz: 'America/Boa_Vista'},
    {id: 26, country: 'Manaus', tz: 'America/Manaus'},
    {id: 27, country: 'Eirunepe', tz: 'America/Eirunepe'},
    {id: 28, country: 'Rio_Branco', tz: 'America/Rio_Branco'},
    {id: 29, country: 'Nassau', tz: 'America/Nassau'},
    {id: 30, country: 'Belize', tz: 'America/Belize'},
    {id: 31, country: 'St_Johns', tz: 'America/St_Johns'},
    {id: 32, country: 'Halifax', tz: 'America/Halifax'},
    {id: 33, country: 'Glace_Bay', tz: 'America/Glace_Bay'},
    {id: 34, country: 'Moncton', tz: 'America/Moncton'},
    {id: 35, country: 'Goose_Bay', tz: 'America/Goose_Bay'},
    {id: 36, country: 'Blanc-Sablon', tz: 'America/Blanc-Sablon'},
    {id: 37, country: 'Toronto', tz: 'America/Toronto'},
    {id: 38, country: 'Nipigon', tz: 'America/Nipigon'},
    {id: 39, country: 'Thunder_Bay', tz: 'America/Thunder_Bay'},
    {id: 40, country: 'Iqaluit', tz: 'America/Iqaluit'},
    {id: 41, country: 'Pangnirtung', tz: 'America/Pangnirtung'},
    {id: 42, country: 'Atikokan', tz: 'America/Atikokan'},
    {id: 43, country: 'Winnipeg', tz: 'America/Winnipeg'},
    {id: 44, country: 'Rainy_River', tz: 'America/Rainy_River'},
    {id: 45, country: 'Resolute', tz: 'America/Resolute'},
    {id: 46, country: 'Rankin_Inlet', tz: 'America/Rankin_Inlet'},
    {id: 47, country: 'Regina', tz: 'America/Regina'},
    {id: 48, country: 'Swift_Current', tz: 'America/Swift_Current'},
    {id: 49, country: 'Edmonton', tz: 'America/Edmonton'},
    {id: 50, country: 'Cambridge_Bay', tz: 'America/Cambridge_Bay'},
    {id: 51, country: 'Yellowknife', tz: 'America/Yellowknife'},
    {id: 52, country: 'Inuvik', tz: 'America/Inuvik'},
    {id: 53, country: 'Creston', tz: 'America/Creston'},
    {id: 54, country: 'Dawson_Creek', tz: 'America/Dawson_Creek'},
    {id: 55, country: 'Fort_Nelson', tz: 'America/Fort_Nelson'},
    {id: 56, country: 'Vancouver', tz: 'America/Vancouver'},
    {id: 57, country: 'Whitehorse', tz: 'America/Whitehorse'},
    {id: 58, country: 'Dawson', tz: 'America/Dawson'},
    {id: 59, country: 'Santiago', tz: 'America/Santiago'},
    {id: 60, country: 'Punta_Arenas', tz: 'America/Punta_Arenas'},
    {id: 61, country: 'Bogota', tz: 'America/Bogota'},
    {id: 62, country: 'Costa_Rica', tz: 'America/Costa_Rica'},
    {id: 63, country: 'Havana', tz: 'America/Havana'},
    {id: 64, country: 'Curacao', tz: 'America/Curacao'},
    {id: 65, country: 'Santo_Domingo', tz: 'America/Santo_Domingo'},
    {id: 66, country: 'Guayaquil', tz: 'America/Guayaquil'},
    {id: 67, country: 'Cayenne', tz: 'America/Cayenne'},
    {id: 68, country: 'Godthab', tz: 'America/Godthab'},
    {id: 69, country: 'Danmarkshavn', tz: 'America/Danmarkshavn'},
    {id: 70, country: 'Scoresbysund', tz: 'America/Scoresbysund'},
    {id: 71, country: 'Cayenne', tz: 'America/Cayenne'},
    {id: 72, country: 'Godthab', tz: 'America/Godthab'},
    {id: 73, country: 'Danmarkshavn', tz: 'America/Danmarkshavn'},
    {id: 74, country: 'Scoresbysund', tz: 'America/Scoresbysund'},
    {id: 75, country: 'Thule', tz: 'America/Thule'},
    {id: 76, country: 'Guatemala', tz: 'America/Guatemala'},
    {id: 77, country: 'Guyana', tz: 'America/Guyana'},
    {id: 78, country: 'Tegucigalpa', tz: 'America/Tegucigalpa'},
    {id: 79, country: 'Port-au-Prince', tz: 'America/Port-au-Prince'},
    {id: 80, country: 'Jamaica', tz: 'America/Jamaica'},
    {id: 81, country: 'Martinique', tz: 'America/Martinique'},
    {id: 82, country: 'Mexico_City', tz: 'America/Mexico_City'},
    {id: 83, country: 'Cancun', tz: 'America/Cancun'},
    {id: 84, country: 'Merida', tz: 'America/Merida'},
    {id: 85, country: 'Monterrey', tz: 'America/Monterrey'},
    {id: 86, country: 'Matamoros', tz: 'America/Matamoros'},
    {id: 87, country: 'Caracas', tz: 'America/Caracas'},
    {id: 88, country: 'Mazatlan', tz: 'America/Mazatlan'},
    {id: 89, country: 'Chihuahua', tz: 'America/Chihuahua'},
    {id: 90, country: 'Ojinaga', tz: 'America/Ojinaga'},
    {id: 91, country: 'Hermosillo', tz: 'America/Hermosillo'},
    {id: 92, country: 'Tijuana', tz: 'America/Tijuana'},
    {id: 93, country: 'Bahia_Banderas', tz: 'America/Bahia_Banderas'},
    {id: 94, country: 'Managua', tz: 'America/Managua'},
    {id: 95, country: 'Panama', tz: 'America/Panama'},
    {id: 96, country: 'Lima', tz: 'America/Lima'},
    {id: 97, country: 'Miquelon', tz: 'America/Miquelon'},
    {id: 98, country: 'Puerto_Rico', tz: 'America/Puerto_Rico'},
    {id: 99, country: 'El_Salvador', tz: 'America/El_Salvador'},
    {id: 100, country: 'Grand_Turk', tz: 'America/Grand_Turk'},
    {id: 101, country: 'Paramaribo', tz: 'America/Paramaribo'},
    {id: 102, country: 'Asuncion', tz: 'America/Asuncion'},
    {id: 103, country: 'Port_of_Spain', tz: 'America/Port_of_Spain'},
    {id: 104, country: 'New_York', tz: 'America/New_York'},
    {id: 105, country: 'Detroit', tz: 'America/Detroit'},
    {id: 106, country: 'Louisville', tz: 'America/Kentucky/Louisville'},
    {id: 107, country: 'Monticello', tz: 'America/Kentucky/Monticello'},
    {id: 108, country: 'Indianapolis', tz: 'America/Indiana/Indianapolis'},
    {id: 109, country: 'Vincennes', tz: 'America/Indiana/Vincennes'},
    {id: 110, country: 'Winamac', tz: 'America/Indiana/Winamac'},
    {id: 111, country: 'Marengo', tz: 'America/Indiana/Marengo'},
    {id: 112, country: 'Petersburg', tz: 'America/Indiana/Petersburg'},
    {id: 113, country: 'Vevay', tz: 'America/Indiana/Vevay'},
    {id: 114, country: 'Tell_City', tz: 'America/Indiana/Tell_City'},
    {id: 115, country: 'Knox', tz: 'America/Indiana/Knox'},
    {id: 116, country: 'Chicago', tz: 'America/Chicago'},
    {id: 117, country: 'Menominee', tz: 'America/Menominee'},
    {id: 118, country: 'Denver', tz: 'America/Denver'},
    {id: 119, country: 'Boise', tz: 'America/Boise'},
    {id: 120, country: 'Phoenix', tz: 'America/Phoenix'},
    {id: 121, country: 'Center', tz: 'America/North_Dakota/Center'},
    {id: 122, country: 'New_Salem', tz: 'America/North_Dakota/New_Salem'},
    {id: 123, country: 'Beulah', tz: 'America/North_Dakota/Beulah'},
    {id: 124, country: 'Los_Angeles', tz: 'America/Los_Angeles'},
    {id: 125, country: 'Anchorage', tz: 'America/Anchorage'},
    {id: 126, country: 'Juneau', tz: 'America/Juneau'},
    {id: 127, country: 'Sitka', tz: 'America/Sitka'},
    {id: 128, country: 'Metlakatla', tz: 'America/Metlakatla'},
    {id: 129, country: 'Yakutat', tz: 'America/Yakutat'},
    {id: 130, country: 'Nome', tz: 'America/Nome'},
    {id: 131, country: 'Adak', tz: 'America/Adak'},
    {id: 132, country: 'Montevideo', tz: 'America/Montevideo'},
  ],
},
{
  id: 5,
  continent: 'Pacific',
  newRow: [
    {id: 1, country: 'Pago_Pago', tz: 'Pacific/Pago_Pago'},
    {id: 2, country: 'Rarotonga', tz: 'Pacific/Rarotonga'},
    {id: 3, country: 'Easter', tz: 'Pacific/Easter'},
    {id: 4, country: 'Galapagos', tz: 'Pacific/Galapagos'},
    {id: 5, country: 'Fiji', tz: 'Pacific/Fiji'},
    {id: 6, country: 'Chuuk', tz: 'Pacific/Chuuk'},
    {id: 7, country: 'Pohnpei', tz: 'Pacific/Pohnpei'},
    {id: 8, country: 'Kosrae', tz: 'Pacific/Kosrae'},
    {id: 9, country: 'Guam', tz: 'Pacific/Guam'},
    {id: 10, country: 'Majuro', tz: 'Pacific/Majuro'},
    {id: 11, country: 'Kwajalein', tz: 'Pacific/Kwajalein'},
    {id: 12, country: 'Tarawa', tz: 'Pacific/Tarawa'},
    {id: 13, country: 'Enderbury', tz: 'Pacific/Enderbury'},
    {id: 14, country: 'Kiritimati', tz: 'Pacific/Kiritimati'},
    {id: 15, country: 'Noumea', tz: 'Pacific/Noumea'},
    {id: 16, country: 'Norfolk', tz: 'Pacific/Norfolk'},
    {id: 17, country: 'Nauru', tz: 'Pacific/Nauru'},
    {id: 18, country: 'Niue', tz: 'Pacific/Niue'},
    {id: 19, country: 'Auckland', tz: 'Pacific/Auckland'},
    {id: 20, country: 'Chatham', tz: 'Pacific/Chatham'},
    {id: 21, country: 'Tahiti', tz: 'Pacific/Tahiti'},
    {id: 22, country: 'Marquesas', tz: 'Pacific/Marquesas'},
    {id: 23, country: 'Gambier', tz: 'Pacific/Gambier'},
    {id: 24, country: 'Port_Moresby', tz: 'Pacific/Port_Moresby'},
    {id: 25, country: 'Bougainville', tz: 'Pacific/Bougainville'},
    {id: 26, country: 'Pitcairn', tz: 'Pacific/Pitcairn'},
    {id: 27, country: 'Palau', tz: 'Pacific/Palau'},
    {id: 28, country: 'Guadalcanal', tz: 'Pacific/Guadalcanal'},
    {id: 29, country: 'Fakaofo', tz: 'Pacific/Fakaofo'},
    {id: 30, country: 'Tongatapu', tz: 'Pacific/Tongatapu'},
    {id: 31, country: 'Funafuti', tz: 'Pacific/Funafuti'},
    {id: 32, country: 'Wake', tz: 'Pacific/Wake'},
    {id: 33, country: 'Honolulu', tz: 'Pacific/Honolulu'},
    {id: 34, country: 'Efate', tz: 'Pacific/Efate'},
    {id: 35, country: 'Wallis', tz: 'Pacific/Wallis'},
    {id: 36, country: 'Apia', tz: 'Pacific/Apia'},
  ],
},
{
  id: 6,
  continent: 'Australia',
  newRow: [
    {id: 1, country: 'Lord_Howe', tz: 'Australia/Lord_Howe'},
    {id: 2, country: 'Hobart', tz: 'Australia/Hobart'},
    {id: 3, country: 'Currie', tz: 'Australia/Currie'},
    {id: 4, country: 'Melbourne', tz: 'Australia/Melbourne'},
    {id: 5, country: 'Sydney', tz: 'Australia/Sydney'},
    {id: 6, country: 'Broken_Hill', tz: 'Australia/Broken_Hill'},
    {id: 7, country: 'Brisbane', tz: 'Australia/Brisbane'},
    {id: 8, country: 'Lindeman', tz: 'Australia/Lindeman'},
    {id: 9, country: 'Adelaide', tz: 'Australia/Adelaide'},
    {id: 10, country: 'Darwin', tz: 'Australia/Darwin'},
    {id: 11, country: 'Perth', tz: 'Australia/Perth'},
    {id: 12, country: 'Eucla', tz: 'Australia/Eucla'},
  ],
},
{
  id: 7,
  continent: 'Africa',
  newRow: [
    {id: 1, country: 'Abidjan', tz: 'Africa/Abidjan'},
    {id: 2, country: 'Algiers', tz: 'Africa/Algiers'},
    {id: 3, country: 'Cairo', tz: 'Africa/Cairo'},
    {id: 4, country: 'El_Aaiun', tz: 'Africa/El_Aaiun'},
    {id: 5, country: 'Ceuta', tz: 'Africa/Ceuta'},
    {id: 6, country: 'Accra', tz: 'Africa/Accra'},
    {id: 7, country: 'Bissau', tz: 'Africa/Bissau'},
    {id: 8, country: 'Nairobi', tz: 'Africa/Nairobi'},
    {id: 9, country: 'Monrovia', tz: 'Africa/Monrovia'},
    {id: 10, country: 'Tripoli', tz: 'Africa/Tripoli'},
    {id: 11, country: 'Casablanca', tz: 'Africa/Casablanca'},
    {id: 12, country: 'Maputo', tz: 'Africa/Maputo'},
    {id: 13, country: 'Windhoek', tz: 'Africa/Windhoek'},
    {id: 14, country: 'Lagos', tz: 'Africa/Lagos'},
    {id: 15, country: 'Khartoum', tz: 'Africa/Khartoum'},
    {id: 16, country: 'Juba', tz: 'Africa/Juba'},
    {id: 17, country: 'Sao_Tome', tz: 'Africa/Sao_Tome'},
    {id: 18, country: 'Ndjamena', tz: 'Africa/Ndjamena'},
    {id: 19, country: 'Tunis', tz: 'Africa/Tunis'},
    {id: 20, country: 'Johannesburg', tz: 'Africa/Johannesburg'},
  ],
},
{
  id: 8,
  continent: 'Atlantic',
  newRow: [
    {id: 1, country: 'Azores', tz: 'Atlantic/Azores'},
    {id: 2, country: 'Bermuda', tz: 'Atlantic/Bermuda'},
    {id: 3, country: 'Madeira', tz: 'Atlantic/Madeira'},
  ],
},
{
  id: 9,
  continent: 'Atlantic',
  newRow: [
    {id: 1, country: 'Cape_Verde', tz: 'Atlantic/Cape_Verde'},
    {id: 2, country: 'Canary', tz: 'Atlantic/Canary'},
    {id: 3, country: 'Stanley', tz: 'Atlantic/Stanley'},
    {id: 4, country: 'Faroe', tz: 'Atlantic/Faroe'},
    {id: 5, country: 'South_Georgia', tz: 'Atlantic/South_Georgia'},
    {id: 6, country: 'Reykjavik', tz: 'Atlantic/Reykjavik'},
  ],
},
{
  id: 10,
  continent: 'Indian',
  newRow: [
    {id: 1, country: 'Cocos', tz: 'Indian/Cocos'},
    {id: 2, country: 'Christmas', tz: 'Indian/Christmas'},
    {id: 3, country: 'Chagos', tz: 'Indian/Chagos'},
    {id: 4, country: 'Mauritius', tz: 'Indian/Mauritius'},
    {id: 5, country: 'Maldives', tz: 'Indian/Maldives'},
    {id: 6, country: 'Mahe', tz: 'Indian/Mahe'},
    {id: 7, country: 'Reunion', tz: 'Indian/Reunion'},
    {id: 8, country: 'Kerguelen', tz: 'Indian/Kerguelen'},
  ],
},

];


来源: stackexchange

问:
Trying to run a calculation inside an if-else statement and it's stalling - C
I'm in an introductory code class for C and I'm trying to run this square and cube calculation if a number greater than 1 is entered, but it stalls if I run it. I'm not getting any errors and I've tried different ways to make this work through tips here, but nothing is happening and I don't know enough to get what's wrong.</p>
```<code>#include <stdio.h>

int main ()
{
    int num, square, cube;

    printf("What is your number? ");
    scanf("%d", num);

    if (num > 1)
    {
        square = num * num;
        cube = num * num * num;

        printf("\nThe square of your number is ");
        printf("%d", &square);
        printf(" and the cube of your number is ");
        printf("%d", cube);
        printf(".");
    }

    printf("\nPlease enter a number greater than 1.");

    return 0;
}
</code>```

答:
You are experiencing a common error called "Segmentation fault" which occurs when you access a memory location which is not allowed.
As others have pointed out, use & operator in scanf while reading the num variable.

ContentLicense: CC BY-SA 4.0

Body:
I'm in an introductory code class for C and I'm trying to run this square and cube calculation if a number greater than 1 is entered, but it stalls if I run it. I'm not getting any errors and I've tried different ways to make this work through tips here, but nothing is happening and I don't know enough to get what's wrong.

#include <stdio.h>

int main ()
{
    int num, square, cube;

    printf("What is your number? ");
    scanf("%d", num);

    if (num > 1)
    {
        square = num * num;
        cube = num * num * num;

        printf("\nThe square of your number is ");
        printf("%d", &square);
        printf(" and the cube of your number is ");
        printf("%d", cube);
        printf(".");
    }

    printf("\nPlease enter a number greater than 1.");

    return 0;
}


问:
Python Immutability List in Tuple - Object or Value?
Can someone help me understand why the second comparison between z and c variables resolve as False?

```<code>t = [1, 2, 3]
h = t
print(id(h), " ", id(t))
print(h is t)

x = ('bla', t)
y = ('bla', t)

z, c = str(x[1]), str(y[1])

print(id(z), " ", id(c))
print(z is c)
</code>```

My initial impression is that x[1] and y[1] would be pointing to the same reference since we're directly assigning that index of the tuples to the t variable. Does this mean Python is passing in the value of t rather than the object of the variable? Why does h is t evaluate to True but z is c evaluate to false? *** scratches head ***

答:
This has nothing to do with tuples themselves, but with str being applied to basically anything that is not already a string (unless a class redefines its __str__ method to cache results):

```<code>x = 0

x is x
# True

str(x) is str(x)
# => False
</code>```

This is because str(x) converts its argument into a new string each time.

Consequently, z and c in your example are different strings that happen to have the same content ('[1, 2, 3]').

Body:
Can someone help me understand why the second comparison between z and c variables resolve as False?

t = [1, 2, 3]
h = t
print(id(h), " ", id(t))
print(h is t)

x = ('bla', t)
y = ('bla', t)

z, c = str(x[1]), str(y[1])

print(id(z), " ", id(c))
print(z is c)

My initial impression is that x[1] and y[1] would be pointing to the same reference since we're directly assigning that index of the tuples to the t variable. Does this mean Python is passing in the value of t rather than the object of the variable? Why does h is t evaluate to True but z is c evaluate to false? *** scratches head ***

Body:
This has nothing to do with tuples themselves, but with str being applied to basically anything that is not already a string (unless a class redefines its __str__ method to cache results):

x = 0

x is x
# True

str(x) is str(x)
# => False

This is because str(x) converts its argument into a new string each time.

Consequently, z and c in your example are different strings that happen to have the same content ('[1, 2, 3]').


问:
Eth private chain sent transaction to smartcontract error "Transaction has been reverted by the EVM"
I'm newbie and now in progress for develop some smartcontract use on ethereum private chain.

I have created KeepPolicy.sol for keep policy data to blockchain, and have dapp for call method in KeepPolicy.sol.

The problem is I got error message in response when call the method. The error message is

{
"message": "Transaction has been reverted by the EVM:\n{\n  "blockHash": "0x11378a4cdaa39bf77b68d8a522d6f337eb897182f6110844e4b6b0b6ea14ef54",\n  "blockNumber": 4349,\n  "contractAddress": null,\n  "cumulativeGasUsed": 23144,\n  "effectiveGasPrice": 0,\n  "from": "0x2013291683023bae332f1e47d378f50265c3d88e",\n  "gasUsed": 23144,\n  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",\n  "status": false,\n  "to": "0xd16ea25805abf4e6defad30e6669fe68dd176aed",\n  "transactionHash": "0xaab5b843ba14d2a4ff63a1a91e64f4fed7bbbdee8c7f13870d2f6132155f8d4a",\n  "transactionIndex": 0,\n  "type": "0x0",\n  "events": {}\n}"
}

and i have some related code here.

send transaction, call setPolicy

```<code>return new Promise(function (resolve, reject) {
    contract.methods.setPolicy(hashId, hashHospitalString, encHospitalString, encPub).send({ from: admin, gas: 100000 })
    .then(function (receipt) {
        if (receipt) {
            console.log('transaction receipt', receipt)
            resolve(receipt)
        }
        resolve({result: false})
    }).catch(function (err) {
        return reject(err)
    })
})
</code>```

KeepPolicy.sol

```<code>// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

contract KeepPolicy {

    struct Policy {
        string hashId;
        string hashHospitalString;
        string encHospitalString;
        string encPub;
    }

    uint256 countId;
    mapping (uint256 => Policy) public policies;

    receive() external payable {}

    function setPolicy(string memory _hashId, string memory _hashHospitalString, string memory _encHospitalString, string memory _encPub)
    external payable {
        uint256 count = countId++;
        policies[count].hashId = _hashId;
        policies[count].hashHospitalString = _hashHospitalString;
        policies[count].encHospitalString = _encHospitalString;
        policies[count].encPub = _encPub;
    }
}
</code>```

答: I close this issue, the problem is about problem when deploy smart contract.</p>

Body:
I'm newbie and now in progress for develop some smartcontract use on ethereum private chain.

I have created KeepPolicy.sol for keep policy data to blockchain, and have dapp for call method in KeepPolicy.sol.

The problem is I got error message in response when call the method. The error message is

{
"message": "Transaction has been reverted by the EVM:\n{\n  "blockHash": "0x11378a4cdaa39bf77b68d8a522d6f337eb897182f6110844e4b6b0b6ea14ef54",\n  "blockNumber": 4349,\n  "contractAddress": null,\n  "cumulativeGasUsed": 23144,\n  "effectiveGasPrice": 0,\n  "from": "0x2013291683023bae332f1e47d378f50265c3d88e",\n  "gasUsed": 23144,\n  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",\n  "status": false,\n  "to": "0xd16ea25805abf4e6defad30e6669fe68dd176aed",\n  "transactionHash": "0xaab5b843ba14d2a4ff63a1a91e64f4fed7bbbdee8c7f13870d2f6132155f8d4a",\n  "transactionIndex": 0,\n  "type": "0x0",\n  "events": {}\n}"
}

and i have some related code here.

send transaction, call setPolicy

return new Promise(function (resolve, reject) {
    contract.methods.setPolicy(hashId, hashHospitalString, encHospitalString, encPub).send({ from: admin, gas: 100000 })
    .then(function (receipt) {
        if (receipt) {
            console.log('transaction receipt', receipt)
            resolve(receipt)
        }
        resolve({result: false})
    }).catch(function (err) {
        return reject(err)
    })
})

KeepPolicy.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

contract KeepPolicy {

    struct Policy {
        string hashId;
        string hashHospitalString;
        string encHospitalString;
        string encPub;
    }

    uint256 countId;
    mapping (uint256 => Policy) public policies;

    receive() external payable {}

    function setPolicy(string memory _hashId, string memory _hashHospitalString, string memory _encHospitalString, string memory _encPub)
    external payable {
        uint256 count = countId++;
        policies[count].hashId = _hashId;
        policies[count].hashHospitalString = _hashHospitalString;
        policies[count].encHospitalString = _encHospitalString;
        policies[count].encPub = _encPub;
    }
}


问:
Thread synchronization in C# using Monitor Wait/Pulse
I have a multi-threaded project in C# that I'm working on, and my idea for controlling the worker thread is not working out as easily as I hoped.

A thread is created when the main GUI window is launched, here is the function it is running:

```<code>    private void continueReading()
    {
        while (true)
        {
            lock (_lock)
            {
                while (!startDAQ)
                    Monitor.Wait(_lock);
                startDAQ = false;
                logging = true;

                daqTaskComponent1.ReadAsync();
            }
        }

    }
</code>```

Now, when a button is clicked on the GUI, startDAQ is set to true, and _lock is pulsed to start the thread calling ReadAsync().

On the Async's callback function, I lock the same _lock object and perform some calculations, then set startDAQ to true and pulse again.

This allows my Async function to be called only when the callback is ready to process more data, and that's how it needs to be.

The problem is I need to be able to pause data collection safely, by causing the continueReading thread to pause on the Monitor.Wait and by allowing a callback to complete if ReadAsync has been called before pausing.

This is the code I'm running when the user clicks the button again to pause data collection:

```<code>    lock (_lock)
    {
        startDAQ = false;
        Monitor.PulseAll(_lock);
        while (logging)
            Monitor.Wait(_lock);
    }
</code>```

This isn't working correctly and I'm getting some deadlocks. This is my first time using Monitor and Wait/Pulsing to signal between threads, so I've been a little stumped, and have a feeling there's an easier way to handle this. Any help or suggestions are appreciated.

EDIT: Here is the relevant code from the callback function:

```<code>    lock (_lock)
    {
        //Lots of code here that just manipulates the data passed to the callback
        startDAQ = true;
        logging = false;
        Monitor.PulseAll(_lock);
    }
</code>```

Added the logging boolean that I forgot when I originally pasted my code.

答: Why don't you simply call ReadAsync from the GUI thread (Since it is already asynchronous), then call it again from the completion callback. No other (explicit) threads or synchronization needed.

ContentLicense: CC BY-SA 3.0

Body:
I have a multi-threaded project in C# that I'm working on, and my idea for controlling the worker thread is not working out as easily as I hoped.

A thread is created when the main GUI window is launched, here is the function it is running:

    private void continueReading()
    {
        while (true)
        {
            lock (_lock)
            {
                while (!startDAQ)
                    Monitor.Wait(_lock);
                startDAQ = false;
                logging = true;

                daqTaskComponent1.ReadAsync();
            }
        }

    }

Now, when a button is clicked on the GUI, startDAQ is set to true, and _lock is pulsed to start the thread calling ReadAsync().

On the Async's callback function, I lock the same _lock object and perform some calculations, then set startDAQ to true and pulse again.

This allows my Async function to be called only when the callback is ready to process more data, and that's how it needs to be.

The problem is I need to be able to pause data collection safely, by causing the continueReading thread to pause on the Monitor.Wait and by allowing a callback to complete if ReadAsync has been called before pausing.

This is the code I'm running when the user clicks the button again to pause data collection:

    lock (_lock)
    {
        startDAQ = false;
        Monitor.PulseAll(_lock);
        while (logging)
            Monitor.Wait(_lock);
    }

This isn't working correctly and I'm getting some deadlocks. This is my first time using Monitor and Wait/Pulsing to signal between threads, so I've been a little stumped, and have a feeling there's an easier way to handle this. Any help or suggestions are appreciated.

EDIT: Here is the relevant code from the callback function:

    lock (_lock)
    {
        //Lots of code here that just manipulates the data passed to the callback
        startDAQ = true;
        logging = false;
        Monitor.PulseAll(_lock);
    }

Added the logging boolean that I forgot when I originally pasted my code.


问:
How to auto increment duplicate values by sequence of repetitions
I'm trying to add an indication of the number of sequence of repetitions of integers in my_list:

```<code>my_list = [20,20,20,30,20,30,40,50,15,11,
           20,40,50,15,20,20,20,50,50]
#my_list.sort()
dup_list = []

for i in range (len(my_list)):
    if my_list[i] not in dup_list:
        dup_list.append(my_list[i])
    else:
        j=1
        res = True
        while res:
            val = my_list[i]+j*0.1
            if val  not in dup_list:
                dup_list.append(val)
                res = False
            j+=1

print(dup_list)
</code>```

the result that I obtain

```<code>[20, 20.1, 20.2, 30, 20.3, 30.1, 40, 50, 15, 11, 20.4, 40.1, 50.1,
 15.1, 20.5, 20.6, 20.7, 50.2, 50.3]
</code>```

The result that I Look for:

```<code>[20.0, 20.0, 20.0, 30.0, 20.1, 30.1, 40.0, 50.0, 15.0, 11.0, 20.2,
 40.1, 50.1, 15.1, 20.3, 20.3, 20.3, 50.2, 50.2]
</code>```

答:
You could use a dictionary dup that you use to keep track of the duplicate values as you iterate over my_list. Update dup whenever a new number is encountered or if a number that is a duplicate but different from the number preceding it:

```<code>out = [my_list[0]]
dup = {out[0]: 0}
for i,j in zip(my_list, my_list[1:]):
    if j in dup:
        if i!=j:
            dup[j] += 0.1
    else:
        dup[j] = 0
    out.append(j+dup[j])
</code>```

Output:

```<code>out = [20.0, 20.0, 20.0, 30.0, 20.1, 30.1, 40.0, 50.0, 15.0, 11.0, 20.2, 40.1, 50.1, 15.1, 20.3, 20.3, 20.3, 50.2, 50.2]
</code>```

Body:
I'm trying to add an indication of the number of sequence of repetitions of integers in my_list:

my_list = [20,20,20,30,20,30,40,50,15,11,
           20,40,50,15,20,20,20,50,50]
#my_list.sort()
dup_list = []

for i in range (len(my_list)):
    if my_list[i] not in dup_list:
        dup_list.append(my_list[i])
    else:
        j=1
        res = True
        while res:
            val = my_list[i]+j*0.1
            if val  not in dup_list:
                dup_list.append(val)
                res = False
            j+=1

print(dup_list)

the result that I obtain

[20, 20.1, 20.2, 30, 20.3, 30.1, 40, 50, 15, 11, 20.4, 40.1, 50.1,
 15.1, 20.5, 20.6, 20.7, 50.2, 50.3]

The result that I Look for:

[20.0, 20.0, 20.0, 30.0, 20.1, 30.1, 40.0, 50.0, 15.0, 11.0, 20.2,
 40.1, 50.1, 15.1, 20.3, 20.3, 20.3, 50.2, 50.2]

Body:
You could use a dictionary dup that you use to keep track of the duplicate values as you iterate over my_list. Update dup whenever a new number is encountered or if a number that is a duplicate but different from the number preceding it:

out = [my_list[0]]
dup = {out[0]: 0}
for i,j in zip(my_list, my_list[1:]):
    if j in dup:
        if i!=j:
            dup[j] += 0.1
    else:
        dup[j] = 0
    out.append(j+dup[j])

Output:

out = [20.0, 20.0, 20.0, 30.0, 20.1, 30.1, 40.0, 50.0, 15.0, 11.0, 20.2, 40.1, 50.1, 15.1, 20.3, 20.3, 20.3, 50.2, 50.2]


答:
As mentioned in the comments, floating point arithmetic is prone to precision issues.Anyway, you can keep track of the current value of every unique item by using a dictionary:

x = [20, 20, 20, 30, 20, 30, 40, 50, 15, 11, 20, 40, 50, 15, 20, 20, 20, 50, 50]
current_values = dict(zip(x, x))

new_x = []
last_seen = x[0]
for item in x:
     if item != last_seen:
         current_values[last_seen] = round(current_values[last_seen] + 0.1, 2)
         last_seen = item
     new_x.append(current_values[item])
```
<p>Result:</p>
<pre class="lang-py prettyprint-override"><code>In [3]: new_x == desired
Out[3]: True
</code>```

Note that since you haven't specified yet what you'd want to do in the case there is more than 10 duplicates, right now you'd start getting 21.0, etc. This should be enough to help you solve your problem and give you something to modify if you need.

Title: How to auto increment duplicate values by sequence of repetitions

Body:
As mentioned in the comments, floating point arithmetic is prone to precision issues.Anyway, you can keep track of the current value of every unique item by using a dictionary:

x = [20, 20, 20, 30, 20, 30, 40, 50, 15, 11, 20, 40, 50, 15, 20, 20, 20, 50, 50]
current_values = dict(zip(x, x))

new_x = []
last_seen = x[0]
for item in x:
     if item != last_seen:
         current_values[last_seen] = round(current_values[last_seen] + 0.1, 2)
         last_seen = item
     new_x.append(current_values[item])

Result:

In [3]: new_x == desired
Out[3]: True

Note that since you haven't specified yet what you'd want to do in the case there is more than 10 duplicates, right now you'd start getting 21.0, etc. This should be enough to help you solve your problem and give you something to modify if you need.


问:
Remove duplicate entries in a list
I have this data:

[
  { "name": "Eric", "origin": "Tristan da Cunha" },
  { "name": "Eric", "origin": "Tristan da Cunha" },
  { "name": "Adelaide", "origin": "Cayman Islands" }
]
```

There is a duplicated data, how do I remove it before converting to a list?

答:
First, make a class for the data, include the hashCode and operator overrides. toString override is optional but would be helpful:

class DataModel {
  String? name;
  String? origin;

  DataModel({this.name, this.origin});

  @override
  int get hashCode => '$name, $origin'.hashCode;

  // this will do the magic
  @override
  bool operator ==(Object other) {
    return other is DataModel &&
        name.toString() == other.name.toString() &&
        origin.toString() == other.origin.toString();
  }

  @override
  String toString() {
    return "{name: '$name', origin: '$origin'}";
  }
}

```
<p>Then, anywhere in your Dart code:</p>
<pre class="lang-dart prettyprint-override"><code>import 'data_model.dart';

void main(List<String> arguments) {
  // notice that Eric is duplicated in this entry
  List<DataModel> filterData = [
    DataModel(name: 'Eric', origin: "Tristan da Cunha"),
    DataModel(name: 'Eric', origin: "Tristan da Cunha"),
    DataModel(name: 'Adelaide', origin: "Cayman Islands"),
  ];

  // toSet() will remove the redundancy, then convert it back to toList()
  var removedDuplicatedDatas = filterData.toSet().toList();
  print(removedDuplicatedDatas);
}
</code>```

Output:

```<code>[{name: 'Eric', origin: 'Tristan da Cunha'}, {name: 'Adelaide', origin: 'Cayman Islands'}]
</code>```

Title: Remove duplicate entries in a list

Body:
I have this data:

[
  { "name": "Eric", "origin": "Tristan da Cunha" },
  { "name": "Eric", "origin": "Tristan da Cunha" },
  { "name": "Adelaide", "origin": "Cayman Islands" }
]

There is a duplicated data, how do I remove it before converting to a list?

Body:
First, make a class for the data, include the hashCode and operator overrides. toString override is optional but would be helpful:

class DataModel {
  String? name;
  String? origin;

  DataModel({this.name, this.origin});

  @override
  int get hashCode => '$name, $origin'.hashCode;

  // this will do the magic
  @override
  bool operator ==(Object other) {
    return other is DataModel &&
        name.toString() == other.name.toString() &&
        origin.toString() == other.origin.toString();
  }

  @override
  String toString() {
    return "{name: '$name', origin: '$origin'}";
  }
}

Then, anywhere in your Dart code:

import 'data_model.dart';

void main(List<String> arguments) {
  // notice that Eric is duplicated in this entry
  List<DataModel> filterData = [
    DataModel(name: 'Eric', origin: "Tristan da Cunha"),
    DataModel(name: 'Eric', origin: "Tristan da Cunha"),
    DataModel(name: 'Adelaide', origin: "Cayman Islands"),
  ];

  // toSet() will remove the redundancy, then convert it back to toList()
  var removedDuplicatedDatas = filterData.toSet().toList();
  print(removedDuplicatedDatas);
}

Output:

[{name: 'Eric', origin: 'Tristan da Cunha'}, {name: 'Adelaide', origin: 'Cayman Islands'}]


问:
why cursor not go to next line? When getline() take "\n" as an input
I was learning from https://www.learncpp.com/cpp-tutorial/an-introduction-to-stdstring/
and a question arises from the below code

```<code>#include <string>
#include <iostream>

int main()
{
    std::cout << "Pick 1 or 2: ";
    int choice{};
    std::cin >> choice;

    std::cout << "Now enter your name: ";
    std::string name{};
    std::getline(std::cin, name); // note: no std::ws here

    std::cout << "Hello, " << name << ", you picked " << choice << '\n';

    return 0;
}
</code>```

the question arising line is

```<code>std::getline(std::cin, name); // note: no std::ws here
</code>```

here above code accepts '\n' as input for std::cin ok!

And the output is below

```<code>Pick 1 or 2: 2
Now enter your name: Hello, , you picked 2
</code>```

Simple!

so my question is why the output does not go in the next line after 'Hello,' because std::cin takes the value "\n"?

the problem is not to buffer! I want to say that the output must print

```<code>Pick 1 or 2: 2
Now enter your name: Hello,
, you picked 2
</code>```

答:
From the documentation for std::getline():

```<code> getline reads characters from an input stream and places them into a string:
 1) Behaves as UnformattedInputFunction, except that input.gcount() is not affected. After constructing and checking the sentry object, performs the following:
    1) Calls str.erase()
    2) Extracts characters from input and appends them to str until one of the following occurs (checked in the order listed)
       a) end-of-file condition on input, in which case, getline sets eofbit.
       b) the next available input character is delim, as tested by Traits::eq(c, delim), in which case the delimiter character is extracted from input, but is not appended to str.
       c) str.max_size() characters have been stored, in which case getline sets failbit and returns.
</code>```

Presumably you are running up against condition (b) above -- the newline character is recognized as a delimiter, "in which case the delimiter character is extracted from input, but is not appended to str"

(if you wanted to, you could do a std::cout << name.size() << '\n'; to see how many characters are in your name string... I suspect you will see that there are zero, since when you just press enter, there are zero characters present before the newline/delimiter character)

Body:
I was learning from https://www.learncpp.com/cpp-tutorial/an-introduction-to-stdstring/
and a question arises from the below code

#include <string>
#include <iostream>

int main()
{
    std::cout << "Pick 1 or 2: ";
    int choice{};
    std::cin >> choice;

    std::cout << "Now enter your name: ";
    std::string name{};
    std::getline(std::cin, name); // note: no std::ws here

    std::cout << "Hello, " << name << ", you picked " << choice << '\n';

    return 0;
}

the question arising line is

std::getline(std::cin, name); // note: no std::ws here

here above code accepts '\n' as input for std::cin ok!

And the output is below

Pick 1 or 2: 2
Now enter your name: Hello, , you picked 2

Simple!

so my question is why the output does not go in the next line after 'Hello,' because std::cin takes the value "\n"?

the problem is not to buffer! I want to say that the output must print

Pick 1 or 2: 2
Now enter your name: Hello,
, you picked 2

Body:
From the documentation for std::getline():

 getline reads characters from an input stream and places them into a string:
 1) Behaves as UnformattedInputFunction, except that input.gcount() is not affected. After constructing and checking the sentry object, performs the following:
    1) Calls str.erase()
    2) Extracts characters from input and appends them to str until one of the following occurs (checked in the order listed)
       a) end-of-file condition on input, in which case, getline sets eofbit.
       b) the next available input character is delim, as tested by Traits::eq(c, delim), in which case the delimiter character is extracted from input, but is not appended to str.
       c) str.max_size() characters have been stored, in which case getline sets failbit and returns.

Presumably you are running up against condition (b) above -- the newline character is recognized as a delimiter, "in which case the delimiter character is extracted from input, but is not appended to str"

(if you wanted to, you could do a std::cout << name.size() << '\n'; to see how many characters are in your name string... I suspect you will see that there are zero, since when you just press enter, there are zero characters present before the newline/delimiter character)


问:
How to assign fields to each tab in WP Gutenberg TabPanel
I know it's a simple question, but I am new in the React and WP Gutenberg world.
I am trying to create a plugin settings page using Gutenberg Components.

The tabs working fine and i know how to render fields, but i can't figure out how to assign to each tab the fields i want.

Here is the sample code:

```<code>import { TabPanel } from '@wordpress/components';

const onSelect = ( tabName ) => {
    console.log( 'Selecting tab', tabName );
};

const MyTabPanel = () => (
    <TabPanel
        className="my-tab-panel"
        activeClass="active-tab"
        onSelect={ onSelect }
        tabs={ [
            {
                name: 'tab1',
                title: 'Tab 1',
                className: 'tab-one',
            },
            {
                name: 'tab2',
                title: 'Tab 2',
                className: 'tab-two',
            },
        ] }
    >
        { ( tab ) => <p>{ tab.title }</p> }
    </TabPanel>
);
</code>```

答:
The Developer guide for Tab Panel mentions that
tabs is an array of objects, which new properties can be added to. By adding a new property, eg content to each of your tab objects, additional components can be set to render for each tab. The simple example uses ( tab ) =>
{ tab.title }
 but this could also include your own custom/existing components defined in content, eg:

```<code>import { Button, TabPanel } from '@wordpress/components';

const onSelect = (tabName) => {
    console.log('Selecting tab', tabName);
};

const MyTabPanel = () => (
    <TabPanel
        className="my-tab-panel"
        activeClass="active-tab"
        onSelect={onSelect}
        tabs={[
            {
                name: 'tab1',
                title: 'Tab 1',
                className: 'tab-one',
                content: <p>Some content goes here</p>
            },
            {
                name: 'tab2',
                title: 'Tab 2',
                className: 'tab-two',
                content: <MyCustomComponent />
            },
        ]}
    >
        {({ title, content, className }) => <div className={className}><h3>{title}</h3>{content}</div>}
    </TabPanel>
);

const MyCustomComponent = () => {
    return <><p>Here is a button</p><Button variant="secondary">Click me!</Button></>;
}
</code>```

The children function (given as anonymous function, above </TabPanel>) renders the tabviews by passing in the active tab object, which now includes the extra content for the tab. The output of the example above is:

Aside from the Developer Guide, the Gutenberg source code is a good place to look for other examples of how TabPanel component can be implemented.. Hope this helps you with adding fields to your tabs..

Body:
I know it's a simple question, but I am new in the React and WP Gutenberg world.
I am trying to create a plugin settings page using Gutenberg Components.

The tabs working fine and i know how to render fields, but i can't figure out how to assign to each tab the fields i want.

Here is the sample code:

import { TabPanel } from '@wordpress/components';

const onSelect = ( tabName ) => {
    console.log( 'Selecting tab', tabName );
};

const MyTabPanel = () => (
    <TabPanel
        className="my-tab-panel"
        activeClass="active-tab"
        onSelect={ onSelect }
        tabs={ [
            {
                name: 'tab1',
                title: 'Tab 1',
                className: 'tab-one',
            },
            {
                name: 'tab2',
                title: 'Tab 2',
                className: 'tab-two',
            },
        ] }
    >
        { ( tab ) =>
{ tab.title }
 }
    </TabPanel>
);

Body:
The Developer guide for Tab Panel mentions that
tabs is an array of objects, which new properties can be added to. By adding a new property, eg content to each of your tab objects, additional components can be set to render for each tab. The simple example uses ( tab ) => <p>{ tab.title }</p> but this could also include your own custom/existing components defined in content, eg:

import { Button, TabPanel } from '@wordpress/components';

const onSelect = (tabName) => {
    console.log('Selecting tab', tabName);
};

const MyTabPanel = () => (
    <TabPanel
        className="my-tab-panel"
        activeClass="active-tab"
        onSelect={onSelect}
        tabs={[
            {
                name: 'tab1',
                title: 'Tab 1',
                className: 'tab-one',
                content: <p>Some content goes here</p>
            },
            {
                name: 'tab2',
                title: 'Tab 2',
                className: 'tab-two',
                content: <MyCustomComponent />
            },
        ]}
    >
        {({ title, content, className }) => <div className={className}><h3>{title}</h3>{content}</div>}
    </TabPanel>
);

const MyCustomComponent = () => {
    return <><p>Here is a button</p><Button variant="secondary">Click me!</Button></>;
}

The children function (given as anonymous function, above </TabPanel>) renders the tabviews by passing in the active tab object, which now includes the extra content for the tab. The output of the example above is:

Aside from the Developer Guide, the Gutenberg source code is a good place to look for other examples of how TabPanel component can be implemented.. Hope this helps you with adding fields to your tabs..


问:
How to kill app on button press
I have an app that has a lot of activities. In the "Settings" page there is a delete account button that is supposed to reset all the saved variables and exit the app. I haven't found a simple solution to exiting the app (eg calling finish only destroys the current activity) What do I call to close the app on a button press (eg when I reopen the the app it should start from the first activity)</p>

答: Try System.exit(0), although you're technically suppose to use finish() on all the activities. This does the same, but quickly.

Title: How to kill app on button press


问:
How to Fix my JavaScript code to succeed in displaying "ON" or "OFF" texts with each click on the checkbox Button?
The idea for me is to add on and off functionality in PHP and Ajax later. But for the moment, I am facing an on and off text display error when activating Visa and Mastercard cards whose HTML code is as follows:

```<code><div class="col-lg-3 mb-lg-0 mb-3">
                <div class="card p-3">
                    <div class="row">
                        <div class="col-8">
                            <div class="img-box"><img src="cardimg/visa.png" alt=""></div>
                            <div class="number"><label class="fw-bold" for="">**** **** **** 1060</label></div>
                        </div>
                        <div class="col-4">
                            <form method="post" class="toggleForm">
                                <div class="custom-control custom-switch">
                                    <input type="checkbox" class="custom-control-input" id="customSwitch1" name='machine_state'>
                                    <label class="custom-control-label" id="statusText1" for="customSwitch1"></label>
                                </div>
                            </form>
                        </div>
                    </div>

                    <div class="row">
                            <small class="col-9">
                                <span class="fw-bold">Expiry date:</span>
                            </small>
                            <small class="col-3">
                                <span>10/16</span>
                            </small>
                    </div>
                </div>
            </div>
            <div class="col-lg-3 mb-lg-0 mb-3">
                <div class="card p-3">
                    <div class="row">
                        <div class="col-8">
                            <div class="img-box"><img src="cardimg/mastercard.png" alt=""></div>
                            <div class="number"><label class="fw-bold" for="">**** **** **** 1060</label></div>
                        </div>
                        <div class="col-4">
                            <form method="post" class="toggleForm">
                                <div class="custom-control custom-switch">
                                    <input type="checkbox" class="custom-control-input" id="customSwitch2" name='machine_state'>
                                    <label class="custom-control-label" id="statusText2" for="customSwitch2"></label>
                                </div>
                            </form>
                        </div>
                    </div>

                    <div class="row">
                            <small class="col-9">
                                <span class="fw-bold">Expiry date:</span>
                            </small>
                            <small class="col-3">
                                <span>10/16</span>
                            </small>
                    </div>
                </div>
            </div>
</code>```

And a 1st JS code of ids customSwitch1 and statusText1:

```<code>function putStatus() {
    $.ajax({
        type: "GET",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_select: true},
        success: function (result) {
            if (result == 1) {
                $('#customSwitch1').prop('checked', true);
                statusText1(1);
            } else {
                $('#customSwitch1').prop('checked', false);
                statusText1(0);
            }
        }
    });
}

function statusText1(status_val) {
    if (status_val == 1) {
        var status_str = "On";
    } else {
        var status_str = "Off";
    }
    document.getElementById("statusText1").innerText = status_str;
}

function onToggle() {
    $('#toggleForm :checkbox').change(function () {
        if (this.checked) {
            //alert('checked');
            updateStatus(1);
            statusText1(1);
        } else {
            //alert('NOT checked');
            updateStatus(0);
            statusText1(0);
        }
    });
}

function updateStatus(status_val) {
    $.ajax({
        type: "POST",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_update: true, status: status_val},
        success: function (result) {
            console.log(result);
        }
    });
}

$(document).ready(function () {
    putStatus();//Set button to current status
    onToggle();//Update when toggled
    statusText1();//Last updated text
});
</code>```

And the second JavaScript code of ids customSwitch2 and statusText2:

```<code>function putStatus() {
    $.ajax({
        type: "GET",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_select: true},
        success: function (result) {
            if (result == 1) {
                $('#customSwitch2').prop('checked', true);
                statusText2(1);
            } else {
                $('#customSwitch2').prop('checked', false);
                statusText2(0);
            }
        }
    });
}

function statusText2(status_val) {
    if (status_val == 1) {
        var status_str = "On";
    } else {
        var status_str = "Off";
    }
    document.getElementById("statusText2").innerText = status_str;
}

function onToggle() {
    $('#toggleForm :checkbox').change(function () {
        if (this.checked) {
            //alert('checked');
            updateStatus(1);
            statusText2(1);
        } else {
            //alert('NOT checked');
            updateStatus(0);
            statusText2(0);
        }
    });
}

function updateStatus(status_val) {
    $.ajax({
        type: "POST",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_update: true, status: status_val},
        success: function (result) {
            console.log(result);
        }
    });
}

$(document).ready(function () {
    putStatus();//Set button to current status
    onToggle();//Update when toggled
    statusText2();//Last updated text
});
</code>```

The problem is that when I click on the Checkbox button, at the HTML page level, I should in principle have a toggle effect that changes from on to off with each click.

But the problem is that the statusText1 and statusText2 representing the on and off texts remain static instead of changing each time the checkbox button is clicked.

So help me to fix my JavaScript code above so that it successfully changes text from on to off every time I click.

Also is there a way to synchronize the use of the Enable and Disable Checkbox Button of the different Ids instead of doing them separately in two different codes which are almost identical ???

答:
I've have fixed the "On" and "Off" issue and "synchronize the use of the Enable and Disable Checkbox Button". Kindly try this code

function putStatus(target) {
    $.ajax({
        type: "GET",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_select: true},
        success: function (result) {
            if (result == 1) {
                $(target).prop('checked', true);
            } else {
                $(target).prop('checked', false);
            }
        }
    });
}

function updateStatus(status_val) {
    $.ajax({
        type: "POST",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_update: true, status: status_val},
        success: function (result) {
            console.log(result);
        }
    });
}

$(document).ready(function () {
    // putStatus('#customSwitch1');
    // putStatus('#customSwitch2');

    $('.statuses').change(function () {
        if($(this).is(':checked')){
            updateStatus(1);
            $(this).next().text('On');
        }else{
            updateStatus(0);
            $(this).next().text('Off');
        }
    });
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
<div class="col-lg-3 mb-lg-0 mb-3">
    <div class="card p-3">
        <div class="row">
            <div class="col-8">
                <div class="img-box"><img src="cardimg/visa.png" alt=""></div>
                <div class="number"><label class="fw-bold" for="">**** **** **** 1060</label></div>
            </div>
            <div class="col-4">
                <form method="post" class="toggleForm">
                    <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input statuses" id="customSwitch1" name="machine_state">
                        <label class="custom-control-label" for="customSwitch1">Off</label>
                    </div>
                </form>
            </div>
        </div>
        <div class="row">
            <small class="col-9">
                <span class="fw-bold">Expiry date:</span>
            </small>
            <small class="col-3">
                <span>10/16</span>
            </small>
        </div>
    </div>
</div>
<div class="col-lg-3 mb-lg-0 mb-3">
    <div class="card p-3">
        <div class="row">
            <div class="col-8">
                <div class="img-box"><img src="cardimg/mastercard.png" alt=""></div>
                <div class="number"><label class="fw-bold" for="">**** **** **** 1060</label></div>
            </div>
            <div class="col-4">
                <form method="post" class="toggleForm">
                    <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input statuses" id="customSwitch2" name="machine_state">
                        <label class="custom-control-label" for="customSwitch2">Off</label>
                    </div>
                </form>
            </div>
        </div>
        <div class="row">
            <small class="col-9">
                <span class="fw-bold">Expiry date:</span>
            </small>
            <small class="col-3">
                <span>10/16</span>
            </small>
        </div>
    </div>
</div></code>```

Body:
The idea for me is to add on and off functionality in PHP and Ajax later. But for the moment, I am facing an on and off text display error when activating Visa and Mastercard cards whose HTML code is as follows:

**** **** **** 1060

                            <form method="post" class="toggleForm">

                                    <input type="checkbox" class="custom-control-input" id="customSwitch1" name='machine_state'>

                            </form>

                                Expiry date:

                                10/16

**** **** **** 1060

                            <form method="post" class="toggleForm">

                                    <input type="checkbox" class="custom-control-input" id="customSwitch2" name='machine_state'>

                            </form>

                                Expiry date:

                                10/16

And a 1st JS code of ids customSwitch1 and statusText1:

function putStatus() {
    $.ajax({
        type: "GET",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_select: true},
        success: function (result) {
            if (result == 1) {
                $('#customSwitch1').prop('checked', true);
                statusText1(1);
            } else {
                $('#customSwitch1').prop('checked', false);
                statusText1(0);
            }
        }
    });
}

function statusText1(status_val) {
    if (status_val == 1) {
        var status_str = "On";
    } else {
        var status_str = "Off";
    }
    document.getElementById("statusText1").innerText = status_str;
}

function onToggle() {
    $('#toggleForm :checkbox').change(function () {
        if (this.checked) {
            //alert('checked');
            updateStatus(1);
            statusText1(1);
        } else {
            //alert('NOT checked');
            updateStatus(0);
            statusText1(0);
        }
    });
}

function updateStatus(status_val) {
    $.ajax({
        type: "POST",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_update: true, status: status_val},
        success: function (result) {
            console.log(result);
        }
    });
}

$(document).ready(function () {
    putStatus();//Set button to current status
    onToggle();//Update when toggled
    statusText1();//Last updated text
});

And the second JavaScript code of ids customSwitch2 and statusText2:

function putStatus() {
    $.ajax({
        type: "GET",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_select: true},
        success: function (result) {
            if (result == 1) {
                $('#customSwitch2').prop('checked', true);
                statusText2(1);
            } else {
                $('#customSwitch2').prop('checked', false);
                statusText2(0);
            }
        }
    });
}

function statusText2(status_val) {
    if (status_val == 1) {
        var status_str = "On";
    } else {
        var status_str = "Off";
    }
    document.getElementById("statusText2").innerText = status_str;
}

function onToggle() {
    $('#toggleForm :checkbox').change(function () {
        if (this.checked) {
            //alert('checked');
            updateStatus(1);
            statusText2(1);
        } else {
            //alert('NOT checked');
            updateStatus(0);
            statusText2(0);
        }
    });
}

function updateStatus(status_val) {
    $.ajax({
        type: "POST",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_update: true, status: status_val},
        success: function (result) {
            console.log(result);
        }
    });
}

$(document).ready(function () {
    putStatus();//Set button to current status
    onToggle();//Update when toggled
    statusText2();//Last updated text
});

The problem is that when I click on the Checkbox button, at the HTML page level, I should in principle have a toggle effect that changes from on to off with each click.

But the problem is that the statusText1 and statusText2 representing the on and off texts remain static instead of changing each time the checkbox button is clicked.

So help me to fix my JavaScript code above so that it successfully changes text from on to off every time I click.

Also is there a way to synchronize the use of the Enable and Disable Checkbox Button of the different Ids instead of doing them separately in two different codes which are almost identical ???

Body:
I've have fixed the "On" and "Off" issue and "synchronize the use of the Enable and Disable Checkbox Button". Kindly try this code

function putStatus(target) {
    $.ajax({
        type: "GET",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_select: true},
        success: function (result) {
            if (result == 1) {
                $(target).prop('checked', true);
            } else {
                $(target).prop('checked', false);
            }
        }
    });
}

function updateStatus(status_val) {
    $.ajax({
        type: "POST",
        url: "https://api.srv3r.com/toggle/",
        data: {toggle_update: true, status: status_val},
        success: function (result) {
            console.log(result);
        }
    });
}

$(document).ready(function () {
    // putStatus('#customSwitch1');
    // putStatus('#customSwitch2');

    $('.statuses').change(function () {
        if($(this).is(':checked')){
            updateStatus(1);
            $(this).next().text('On');
        }else{
            updateStatus(0);
            $(this).next().text('Off');
        }
    });
});

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
<div class="col-lg-3 mb-lg-0 mb-3">
    <div class="card p-3">
        <div class="row">
            <div class="col-8">
                <div class="img-box"><img src="cardimg/visa.png" alt=""></div>
                <div class="number"><label class="fw-bold" for="">**** **** **** 1060</label></div>
            </div>
            <div class="col-4">
                <form method="post" class="toggleForm">
                    <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input statuses" id="customSwitch1" name="machine_state">
                        <label class="custom-control-label" for="customSwitch1">Off</label>
                    </div>
                </form>
            </div>
        </div>
        <div class="row">
            <small class="col-9">
                <span class="fw-bold">Expiry date:</span>
            </small>
            <small class="col-3">
                <span>10/16</span>
            </small>
        </div>
    </div>
</div>
<div class="col-lg-3 mb-lg-0 mb-3">
    <div class="card p-3">
        <div class="row">
            <div class="col-8">
                <div class="img-box"><img src="cardimg/mastercard.png" alt=""></div>
                <div class="number"><label class="fw-bold" for="">**** **** **** 1060</label></div>
            </div>
            <div class="col-4">
                <form method="post" class="toggleForm">
                    <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input statuses" id="customSwitch2" name="machine_state">
                        <label class="custom-control-label" for="customSwitch2">Off</label>
                    </div>
                </form>
            </div>
        </div>
        <div class="row">
            <small class="col-9">
                <span class="fw-bold">Expiry date:</span>
            </small>
            <small class="col-3">
                <span>10/16</span>
            </small>
        </div>
    </div>
</div>