In my angular 2 application I have declared 2 object arrays.
users: User[];
selectedUsers: User[];
Now I am using the filter() method to return an array with objects whose checked property is true.
this.selectedUsers = this.users.filter(user => user.isChecked == true);
The problem is the references for elements of both arrays are same. So is there a way to that I can filter out objects and return array of new objects(new reference)?
You can always use Array.prototype.map to create a new array and Object.assign to create a new object:
this.users.filter(user => user.isChecked).map(u => Object.assign({},u));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With