0

I have a Map that contains keys and their value. I want to convert all keyvalues into an array

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'],
]);

I want that my new array should look like this

['⚽ GOAL','πŸ” Substitution','⚽ GOAL' ,'πŸ” Substitution', 'πŸ”Ά Yellow card', 'πŸ”΄ Red card', 'πŸ” Substitution','πŸ” Substitution',, '⚽ GOAL', '⚽ GOAL', 'πŸ”Ά Yellow card']

2 Answers 2

1

this will do

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()]);

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

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]))

1 Comment

Uncaught TypeError: gameEvents.map is not a function I'm facing the above problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.