0

can i remove a data that refers to an array of string?

i already get the answer for group some group_id in my question create new array from nested array object

but i have some questions left

from some response data, I want to remove certain data from array

this is the filter data

const filterArray = [
{
    name: "smash",
    id: "012112",
group_id: ["01","03"]
  },
  {
    name: "ahlan wa sahlan",
    id: "123123",
group_id: ["01","03"]
  }
];

response data from api

const group_one = [
     {
        name: "smash",
        id: "012112"
      },
      {
        name: "ahlan wa sahlan",
        id: "123123"
      },
          {
            name: "ahh",
            id: "1231239"
          },
          {
            name: "laki",
            id: "21312"
          }
        ];
        
        const group_two = [
          {
            name: "ahh",
            id: "1231239"
          },
          {
            name: "laki",
            id: "21312"
          }
        ];
        
      const group_three = [
      {
        name: "smash",
        id: "012112"
      },
      {
        name: "ahlan wa sahlan",
        id: "123123"
      },
    ];
    
    const data = [
              {
                body: group_one,
                group_id: "01"
              },
              {
                body: grouop_two,
                group_id: "02"
              },
              {
                body: group_three,
                group_id: "03"
              }
            ];
        

expected results

const group_one = [
      {
        name: "ahh",
        id: "1231239"
      },
      {
        name: "laki",
        id: "21312"
      }
    ];
    
    const group_two = [
      {
        name: "ahh",
        id: "1231239"
      },
      {
        name: "laki",
        id: "21312"
      }
    ];
    
    const group_three = [];

const data = [
          {
            body: group_one,
            group_id: "01"
          },
          {
            body: grouop_two,
            group_id: "02"
          },
          {
            body: group_three,
            group_id: "03"
          }
        ];

can someone help me? with articles or codes or any good practice. thanks for helping me (sry for my bad english)

  • it easier to keep track if it in the array, otherwise you have to name each varibles, like you list above( `group_one`, `group_two`,..). And to remove property of obj, use `delete`: `filterArray.forEach(el => delete el.group_id)` – Mike Aug 03 '21 at 18:00

0 Answers0