1

In order to feed some chartjs, I need to get from the following

enter image description here

a new array with all values like [0, 1, 0, 0, 0, 0.324, 0.25, 0.71...]. I've been playing with map but without success, I'm definitely missing something. Any help/input appreciated. Thank you

Panda
  • 91
  • 2
  • 4
  • 12
  • [`Object.values`....](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values) – Jared Smith Feb 21 '21 at 17:22

1 Answers1

1

Not sure if you want all the values or the ones highlighted, try this:

const data = [
  {a:1,b:1,c:1,d:1},
  {a:2,b:2,c:2,d:2},
  {a:3,b:3,c:3,d:3},
];

const getDataFromObj = (obj={}) => {
  const { a, b, c } = obj; return Object.values({ a, b, c });
}

// get a, b, and c values of data[0]
console.log( getDataFromObj(data[0]) );

// get a, b, and c values of data items
console.log( data.map(getDataFromObj) );

// get all values of data items
console.log( data.map(Object.values) );
Majed Badawi
  • 27,616
  • 4
  • 25
  • 48