-4

Please I will like to convert :

const words = {told: 64,
               mistake: 11,
               thought: 16,
               bad: 17}

TO

const words = [ 
  {text: 'told', value: 64,},
  {text: 'mistake', value: 11,},
  {text: 'thought', value: 16,},
  {text: 'bad', value: 17,
  },
]

Thanks a lot

1
  • 1
    Object entries and map Commented Jan 23, 2021 at 17:00

1 Answer 1

0

You can use Object.entries() to loop over object's (keys & values):

const data = {told: 64,
               mistake: 11,
               thought: 16,
               bad: 17
             };
const words = Object.entries(data).map(([text, value]) => ({text, value}));
console.log(words);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.