matanox
matanox

Reputation: 13716

Javascript: is it safe to assign the result of array.filter() to the same array

Is it officially safe to:

someArray = someArray.filter(function(item) {
              return item !== 'something';
            });

I mean assigning back to the same array the filter function is called for, in one line. And same question for all other array prototype functions that return an array.

Upvotes: 3

Views: 887

Answers (1)

Codeman
Codeman

Reputation: 12375

Yes, it's safe because it's returning the value from the function.

You should be careful about making sure you're reusing it correctly, though.

Upvotes: 3

Related Questions