-6
         const {city, country} = input.split(/\s*,\s*/);

These are both undefined.

Input is los gatos, california

chovy
  • 72,281
  • 52
  • 227
  • 295

1 Answers1

5

.split results in an array output but you're destructuring it as if it were an object.

Do

const [city, country] = 'los gatos, california'.split(/\s*,\s*/);
console.log(city);
console.log(country);

You destructure by using array destructuring ([..]) instead of object ({..})

Lain
  • 3,657
  • 1
  • 20
  • 27
Azarro
  • 1,776
  • 1
  • 4
  • 11