What is immutability and why should I worry about it?

What is Immutability? Immutability is applied primarily to objects (strings, arrays, a custom Animal class) Typically, if there is an immutable version of a class, a mutable version is also available. For instance, Objective-C and Cocoa define both an NSString class (immutable) and an NSMutableString class. If an object is immutable, it can’t be changed … Read more

Update one of the objects in array, in an immutable way

You can use map to iterate the data and check for the fieldName, if fieldName is cityId then you need to change the value and return a new object otherwise just return the same object. Write it like this: var data = [ {fieldName: ‘title’, valid: false}, {fieldName: ‘description’, valid: true}, {fieldName: ‘cityId’, valid: false}, … Read more