_.without
returns a new array, see docs, so you are effectively changing where folders
is pointing to. However, since you are calling _.without
only once the promise resolves, i.e. inside then
this change will occur only after you have returned the original folders
object so you end up with two references pointing to different arrays.
It's probably best practice to return the actual promise from inside your factory, this way you can reference the correct data once the promise returns.