方法一:map()

let cities =  [
  {city:"北京",bOn:false},
  {city:"上海",bOn:false},
  {city:"重庆",bOn:false},
  {city:"广州",bOn:false},
  {city:"西安",bOn:false}
];
 let city = cities.map((item) =>{
   return item.city
 });
 console.log('city == ',city);

 

方法二:foreach()(你用for也行,哈哈哈)
let cities =  [
  {city:"北京",bOn:false},
  {city:"上海",bOn:false},
  {city:"重庆",bOn:false},
  {city:"广州",bOn:false},
  {city:"西安",bOn:false}
];
 let city = [];
 cities.forEach((item)=>{
    city.push(item.city);
 });
 console.log('city == ',city);

 

相关文章:

  • 2021-11-19
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-11-29
  • 2021-12-19
  • 2022-12-23
相关资源
相似解决方案