我有一个Map,其中包含键和它们的值。我希望将所有键值转换为数组。
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']发布于 2021-01-20 05:32:34
这就行了
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()]);
发布于 2021-01-20 05:29:54
试试这个:
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]))
https://stackoverflow.com/questions/65803561
复制相似问题