How to collect values of object properties into a list?

1👍

you can use map method

var data=[
    {
        "date__month": 8,
        "price__sum": 999.0
    },
    {
        "date__month": 9,
        "price__sum": 999.0
    },
    {
        "date__month": 10,
        "price__sum": 888.0
    },
    {
        "date__month": 11,
        "price__sum": 777.0
    }
];
var mapped=data.map(i=>i.price__sum);

console.log(mapped)

👍:1

Iterate over the array you have and push the price__sum values onto a new one.

let originalArray = [{
    "date__month": 8,
    "price__sum": 999.0
  },
  {
    "date__month": 9,
    "price__sum": 999.0
  },
  {
    "date__month": 10,
    "price__sum": 888.0
  },
  {
    "date__month": 11,
    "price__sum": 777.0
  }
]
let newArray = [];

originalArray.forEach((item)=> newArray.push(item.price__sum));

console.log(newArray);

Leave a comment