Add elements to an array, according to the value of another array

I have two arrays:

  1. video, brings objects with the following elements: id, title and url.
  2. watched_videos, brings objects with the
    following elements: watched, video_id.

I need to check which objects in the video array have an id equal to video_id, all that satisfy this condition, add a new element called watched, with a value of true, those that do not, add a watched, with a value of false.

I know I can do this using the filter and include functions to manipulate the arrays, however, I can’t understand a way that works.

I’m learning about handling arrays.

Edit:
@Prerak Sola
I stopped here, when I tried to check if there is an identical id in watched_videos.

const module_videos = videos.filter((v) =>
  v.id.include(watched_videos.video_id)
);

I’m getting the error: "v.id.include is not a function",

Edit 2:

I need to receive the following result:

videos = [{
    "id": 1,
    "title": "one",
    "url": "/v1",
    "watched": true
  }, {
    "id": 2,
    "title": "two",
    "url": "/v2"
    "watched": false
  }
];

16 thoughts on “Add elements to an array, according to the value of another array”

Leave a Comment