Why can you programmatically (in a loop) add a property to an array element, while the given element is a string, like this:

arr.map((obj, i) => { obj.active = true }) 

Do you have to write such a property with your hands (or can you?)

  • because any object, if it has not been frozen, you can add a property. In addition, if the collection item itself is changing, and you do not need to get a new one, it is better to use forEach instead of map - Grundy
  • and how can you add a property to an array element with hands if the element is a string? - Den Rash
  • one
    obj.active = true , and maybe not :-) only if you create a string object , via new String . With primitives - does not work. - Grundy

0