[Vuejs]-How can I store the attributes of objects of an array in array?

1👍

You can use this expression:

campaigns.displays.map( ({name}) => name );
const campaigns = { displays: [{ name: 'info1'}, { name: 'info2'}] };

const result = campaigns.displays.map( ({name}) => name );

console.log(result);

0👍

This will display an array containing the property names of each object in the displays array

    var data = {
      displays: [
        {
          capacity: 9000,
          id: 1,
          imei: 44596
        }
      ]
    };
    data.displays.forEach(function(obj, idx) {
      console.log(Object.keys(obj));
    });

Object.keys() is what you need

Leave a comment