Javascript 从对象中删除标识符

Javascript 从对象中删除标识符,javascript,object,Javascript,Object,我有一个具有标识符的对象: const cities = { "0": { "city": "Bielsko-Biała", "country": "PL", }, "1": { "city": "Kielce", "country": "PL", }, "2": { "city": "Kłodzko", "country": "PL", } } 我想要的是删除0、1、2等以获得此格式: const cities = [

我有一个具有标识符的对象:

const cities = {
  "0": {
    "city": "Bielsko-Biała",
    "country": "PL",
  },
  "1": {
    "city": "Kielce",
    "country": "PL",
  },
  "2": {
    "city": "Kłodzko",
    "country": "PL",
  }
}
我想要的是删除0、1、2等以获得此格式:

const cities = [
   {
    "city": "Bielsko-Biała",
    "country": "PL",
  },
 {
    "city": "Kielce",
    "country": "PL",
  },
  {
    "city": "Kłodzko",
    "country": "PL",
  }
]
这对我来说是必要的,因为我想为每个城市添加描述,但由于该格式,我无法在此对象中映射

我必须在React中执行类似的操作,我认为这是一个非常糟糕的编写代码:

const cities = [];

countries.map(el => {
  cities.push(el.city)
})

let updatedCountries = countries;

cities.forEach((city) => {
  axios.get(`https://en.wikipedia.org/api/rest_v1/page/summary/${city}`)
    .then(response => {
      for (let property in updatedCountries) {
        if (updatedCountries.hasOwnProperty(property)) {
          if (updatedCountries[property].city === city) {
            updatedCountries[property]['description'] = response.data.description
          }
        }
      }
    })
})

this.setState({
  countries: updatedCountries
})
你可以用

Object.values()
方法返回给定对象自身可枚举属性值的
数组

const cities={
"0": {
“城市”:“别尔斯科·比亚尼亚”,
“国家”:“PL”,
},
"1": {
“城市”:“基尔切”,
“国家”:“PL”,
},
"2": {
“城市”:“科兹科”,
“国家”:“PL”,
}
}
让值=对象。值(城市);
console.log(值)您可以使用

Object.values()
方法返回给定对象自身可枚举属性值的
数组

const cities={
"0": {
“城市”:“别尔斯科·比亚尼亚”,
“国家”:“PL”,
},
"1": {
“城市”:“基尔切”,
“国家”:“PL”,
},
"2": {
“城市”:“科兹科”,
“国家”:“PL”,
}
}
让值=对象。值(城市);
console.log(值)