[Vuejs]-Append property to each object within array

0๐Ÿ‘

โœ…

If you use ES6, you can do one liner like that:

var users = [
    { name: 'John', age: 25 },
    { name: 'Jane', age: 28 }
];

users.map(user => user.edit = false);

0๐Ÿ‘

Use map and spread operator

const users = [
    { name: 'John', age: 25 },
    { name: 'Jane', age: 28 }
];

const usersUpdated = users.map(user => ({ ...user, edit: false }));

Leave a comment