How to add new property in array of objects using JavaScript

Sometimes we need to modify some arrays for tons of possible reasons.
Let me give you a real-world example.

Think about you’re working on a Vue.js project and your task is creating a tabs navigation.
You sent the request to the endpoint and got a response like this:

[
  {
    id: 1,
    title: 'Some title',
    content: 'Some content',
  },
  {
    id: 2,
    title: 'Some title',
    content: 'Some content',
  },
  {
    id: 3,
    title: 'Some title',
    content: 'Some content',
  },
  {
    id: 4,
    title: 'Some title',
    content: 'Some content',
  }
]

First of all, you need some kind of property in this objects of array, like “isActive” to show or hide the corresponding tab based on this property value.
The easiest and shortest thing you can do is using map() function and modify every object in the array.

As you can see in the console, I’ve added “isActive” property to all objects and only for the first object I’ve this true to make the first tab active as default.