Transform one-dimensional multidimensional array into VUE

-1

I need to transform a multidimensional array into VUE into a one-dimensional array, since I need to retrieve an array only with the "cod" fields of that array,

new Vue({
    el:"#app",
    data : {
        array_teste : [{cod : '1', nome : 'S'},{cod : '2', nome : 'V'}],
    },

    computed: {
        cat_vender_rec: function() {
            return JSON.stringify(this.cat_vender);
        }
    }       
})
    
asked by anonymous 18.12.2018 / 03:08

1 answer

2

You can use the .map() method to map the array data you want.

const array = [{cod : '1', nome : 'S'},{cod : '2', nome : 'V'}];

const arrayCods = array.map(obj => {
  return obj.cod;    
});

console.log(arrayCods); // ['1', '2']

Method documentation .map ()

p>     
18.12.2018 / 12:15