I'm trying to modify an element in a list in Vue.js using .filter() method. The new element comes from Pusher. I'm listening for the event and trying to update the element like this:
users.filter((obj) => { Echo.private(`user.${obj.id}`).listen('.userupdated', (e) => { return obj = e.user; // or return e.user; also doesn't work }); }); This doesn't work. Both objects are identical in terms of their structure, but the new object coming through Pusher contains the updated information.
On the other hand, when I try to modify a property, it works:
users.filter((obj) => { Echo.private(`user.${obj.id}`).listen('.userupdated', (e) => { return obj.name = e.user.name; }); }); What am I doing wrong? Is replacing an entire element like this isn't allowed?
.filter()method. It doesn't sound a good use case forfilter.obj.nameworks becauseobjby itself is a reference that points to an object, so you are modifying the underlying object by doingobj.name = e.user.name. While withobj = e.user, you are overwriting theobjvariable which doesn't affect what references are stored in the original array.return. You are not returning to the outer function from that callback because returns don't work that way