如何将数组对象转换为数组数组?

Gre*_*rts 0 javascript arrays methods

我现在有一个数组对象。该函数应返回一个包含所有对象值的数组的数组。错误在哪里?

const car = [
  {  
    "name":"BMW",
    "price":"55 000",
    "country":"Germany",
    "security":"Hight"
  },
  {  
    "name":"Mitsubishi",
    "price":"93 000", 
    "constructor":"Bar John",
    "door":"3",
    "country":"Japan",
  },
  {  
    "name":"Mercedes-benz",
    "price":"63 000", 
    "country":"Germany",
    "security":"Hight"
  }
 ];

function cars(car){
  return car.map(function(key) {
    return [[key]];
  });
}
console.log(cars(car));
Run Code Online (Sandbox Code Playgroud)

Nin*_*olz 5

您可以返回对象的值。

function cars(car){
    return car.map(Object.values);
}

const car = [{ name: "BMW", price: "55 000", country: "Germany", security: "Hight" }, { name: "Mitsubishi", price: "93 000", constructor: "Bar John", door: "3", country: "Japan" }, { name: "Mercedes-benz", price: "63 000", country: "Germany", security: "Hight" }];

console.log(cars(car));
Run Code Online (Sandbox Code Playgroud)
.as-console-wrapper { max-height: 100% !important; top: 0; }
Run Code Online (Sandbox Code Playgroud)