Skip to content

Instantly share code, notes, and snippets.

@jakoblind
Created June 6, 2015 15:57
Show Gist options
  • Save jakoblind/462472879b4150760383 to your computer and use it in GitHub Desktop.
Save jakoblind/462472879b4150760383 to your computer and use it in GitHub Desktop.
var list1 = [{a: 1}, {b: 2}, {c:3}];
var list2 = _.map(list1, function(i){
i = "test";
return "test";
});
//list1 is not changed but a new list is created:
//JSON.stringify(list1): "[{"a":1},{"b":2},{"c":3}]"
//JSON.stringify(list2); "["test","test","test"]"
var list3 = _.map(list1, function(i){
i.a = "hello";
return "test";
});
//list1 is changed:
//JSON.stringify(list1) "[{"a":"hello"},{"b":2,"a":"hello"},{"c":3,"a":"hello"}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment