1

I have this code

console.log({Stats:Object.fromEntries(['score','count','w','l','d'].map(s=>[s,teamsToPlay[0][s]]))}) 

//Stats: { score:123 count:22 w:12 l:10 d:0 }

How can I extract value/number of each entry?

I tried

const d = ({Stats:Object.fromEntries(['d'].map(s=>[s,teamsToPlay[0][s]]))}).match(/\d+/);

but it gives

{(intermediate value)}.match is not a function

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • 1
    Does this answer your question? [How to get all properties values of a JavaScript Object (without knowing the keys)?](https://stackoverflow.com/questions/7306669/how-to-get-all-properties-values-of-a-javascript-object-without-knowing-the-key) – Heretic Monkey Nov 05 '21 at 19:58

1 Answers1

0

This is not the best solution but it worked for me:

var swin = {Stats: Object.fromEntries(['w'].map(s => [s, teamsToPlay[0][s]]))};
var scount = {Stats: Object.fromEntries(['count'].map(s => [s, teamsToPlay[0][s]]))};
swin = JSON.stringify(swin);
scount = JSON.stringify(scount);
swin = swin.match(/\d+/);
scount = scount.match(/\d+/);