[Vuejs]-Using join() on array nested in object entries from vuex getter

1πŸ‘

βœ…

I don’t think it’s possible with a single line. You can achieve it in this way:

const getters = {
    errors: (state) => {
       let newErrors = {};
       Object.keys(state.errors).map( key => newErrors[key] = state.errors[key].join(' ') )
       return newErrors;
    }
};
πŸ‘€Fab

2πŸ‘

A reducer should work for the one liner.

const getters = {
  errors: state => Object.keys(state.errors).reduce((acc, key) => {
    acc[key] = state.errors[key].join(' ')
    return acc
  }, {})
};
πŸ‘€Borjante

Leave a comment