JavaScript 如何将 Map 键值转换为数组

How to convert Map key values into array in JavaScript

我有一个包含键及其值的映射。我想将所有键值转换成一个数组

const gameEvents = new Map([
  [17, '⚽ GOAL'],
  [36, ' Substitution'],
  [47, '⚽ GOAL'],
  [61, ' Substitution'],
  [64, ' Yellow card'],
  [69, ' Red card'],
  [70, ' Substitution'],
  [72, ' Substitution'],
  [76, '⚽ GOAL'],
  [80, '⚽ GOAL'],
  [92, ' Yellow card'],
]);

我希望我的新数组看起来像这样

['⚽ GOAL',' Substitution','⚽ GOAL' ,' Substitution', ' Yellow card', ' Red card', ' Substitution',' Substitution',, '⚽ GOAL', '⚽ GOAL', ' Yellow card']

试试这个:

const gameEvents = [
  [17, '⚽ GOAL'],
  [36, ' Substitution'],
  [47, '⚽ GOAL'],
  [61, ' Substitution'],
  [64, ' Yellow card'],
  [69, ' Red card'],
  [70, ' Substitution'],
  [72, ' Substitution'],
  [76, '⚽ GOAL'],
  [80, '⚽ GOAL'],
  [92, ' Yellow card'],
];

console.log(gameEvents.map(x => x[1]))

这样就可以了

const gameEvents = new Map([
  [17, '⚽ GOAL'],
  [36, ' Substitution'],
  [47, '⚽ GOAL'],
  [61, ' Substitution'],
  [64, ' Yellow card'],
  [69, ' Red card'],
  [70, ' Substitution'],
  [72, ' Substitution'],
  [76, '⚽ GOAL'],
  [80, '⚽ GOAL'],
  [92, ' Yellow card'],
]);

console.log([...gameEvents.values()]);