根据另一个对象数组修改一个对象数组

时间:2019-12-16 14:53:51

标签: javascript arrays

我有一个带有parent product选项的数组:

"options": [
      {
        "_id": "5ce3f95d35ad1e0999ee18db",
        "sort_order": 0,
        "values": [
          {
            "_id": "5ce3f95d35ad1e0999ee18dc",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 6 / 38",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18dd",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 6.5 / 39",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18de",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 7 / 39.5",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18df",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 7.5 / 40",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e0",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 8 / 41",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e1",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 8.5 / 41.5",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e2",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 9 / 42",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e3",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 9.5 / 42.5",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e4",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 10 / 43",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e5",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 10.5 / 44",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e6",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 11 / 44.5",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e7",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 11.5 / 45",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e8",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 12 / 46",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18e9",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 12.5 / 46.5",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          },
          {
            "_id": "5ce3f95d35ad1e0999ee18ea",
            "is_default": false,
            "is_required": true,
            "sort_order": 0,
            "value": "",
            "label": "No 13 / 47",
            "option_id": "5ce3f95d35ad1e0999ee18db",
            "__v": 0
          }
        ],
        "name": "ΥΠΟΔΥΣΗ | USA / EU ΜΕΓΕΘΗ 6/38 - 13/47",
        "display_name": "Μέγεθος (USA / EU)",
        "type": "text",
        "display_style": "dropdown",
        "__v": 0
      },
      {
        "_id": "5df780dc603399b430e7b247",
        "display_name": "swatch",
        "display_style": "swatch",
        "is_required": true,
        "name": "Χρωματα",
        "option_id": "",
        "option_set_id": "",
        "sort_order": 0,
        "type": "swatch",
        "values": [
          {
            "label": "Μονοκολορ",
            "sort_order": 0,
            "value": "",
            "_id": "5df780dc603399b430e7b248"
          },
          {
            "_id": "5df780ec603399b430e7b249",
            "is_default": false,
            "is_required": true,
            "label": "Δικολορ",
            "sort_order": 0,
            "value": "#363030|#cd1bce",
            "value_data": null
          },
          {
            "_id": "5df780f7603399b430e7b24a",
            "is_default": false,
            "is_required": true,
            "label": "Τρικολορ",
            "sort_order": 0,
            "value": "#33cfb0|#308464|#819bca",
            "value_data": null
          }
        ]
      }
    ]

我也有variants的数组:

[{
    "_id": "5df7812f136d32086e605bae",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18dc",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 6 / 38",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "label": "Μονοκολορ",
          "sort_order": 0,
          "value": "",
          "_id": "5df780dc603399b430e7b248"
        }
      }
    ],
  },
  {
    "_id": "5df7812f136d32086e605bb2",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18dd",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 6.5 / 39",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "_id": "5df780ec603399b430e7b249",
          "is_default": false,
          "is_required": true,
          "label": "Δικολορ",
          "sort_order": 0,
          "value": "#363030|#cd1bce",
          "value_data": null
        }
      }
    ],
  },
  {
    "_id": "5df7812f136d32086e605bc3",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18e3",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 9.5 / 42.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "label": "Μονοκολορ",
          "sort_order": 0,
          "value": "",
          "_id": "5df780dc603399b430e7b248"
        }
      }
    ],
  },
  {
    "_id": "5df7812f136d32086e605bcd",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18e6",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 11 / 44.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "_id": "5df780ec603399b430e7b249",
          "is_default": false,
          "is_required": true,
          "label": "Δικολορ",
          "sort_order": 0,
          "value": "#363030|#cd1bce",
          "value_data": null
        }
      }
    ]
  }
]

options的{​​{1}}数组具有产品可能拥有的所有parent product,但是variants数组的库存量大于variants的变体

如何更改/过滤0的{​​{1}}数组,使其仅包含optionsparent product的{​​{1}}数组?

示例输出:(如果我只有option的大小和values的颜色来自变体数组)

variants

这是我到目前为止尝试过的:

No 6/38

为了方便起见,我在这里准备了一个游乐场:https://codesandbox.io/s/friendly-curie-9pz41

2 个答案:

答案 0 :(得分:0)

您可以使用filtersome方法:

const result = options.filter(f => 
     f.values.some(s=> variants.some(v1 => 
          v1.options.some(v2 => v2.value.value == s.value))));

一个例子:

const options = [
    {
      "_id": "5ce3f95d35ad1e0999ee18db",
      "sort_order": 0,
      "values": [
        {
          "_id": "5ce3f95d35ad1e0999ee18dc",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 6 / 38",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18dd",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 6.5 / 39",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18de",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 7 / 39.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18df",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 7.5 / 40",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e0",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 8 / 41",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e1",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 8.5 / 41.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e2",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 9 / 42",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e3",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 9.5 / 42.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e4",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 10 / 43",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e5",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 10.5 / 44",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e6",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 11 / 44.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e7",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 11.5 / 45",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e8",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 12 / 46",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18e9",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 12.5 / 46.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        },
        {
          "_id": "5ce3f95d35ad1e0999ee18ea",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 13 / 47",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      ],
      "name": "ΥΠΟΔΥΣΗ | USA / EU ΜΕΓΕΘΗ 6/38 - 13/47",
      "display_name": "Μέγεθος (USA / EU)",
      "type": "text",
      "display_style": "dropdown",
      "__v": 0
    },
    {
      "_id": "5df780dc603399b430e7b247",
      "display_name": "swatch",
      "display_style": "swatch",
      "is_required": true,
      "name": "Χρωματα",
      "option_id": "",
      "option_set_id": "",
      "sort_order": 0,
      "type": "swatch",
      "values": [
        {
          "label": "Μονοκολορ",
          "sort_order": 0,
          "value": "",
          "_id": "5df780dc603399b430e7b248"
        },
        {
          "_id": "5df780ec603399b430e7b249",
          "is_default": false,
          "is_required": true,
          "label": "Δικολορ",
          "sort_order": 0,
          "value": "#363030|#cd1bce",
          "value_data": null
        },
        {
          "_id": "5df780f7603399b430e7b24a",
          "is_default": false,
          "is_required": true,
          "label": "Τρικολορ",
          "sort_order": 0,
          "value": "#33cfb0|#308464|#819bca",
          "value_data": null
        }
      ]
    }
  ]

  const variants =[{
    "_id": "5df7812f136d32086e605bae",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18dc",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 6 / 38",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "label": "Μονοκολορ",
          "sort_order": 0,
          "value": "",
          "_id": "5df780dc603399b430e7b248"
        }
      }
    ],
  },
  {
    "_id": "5df7812f136d32086e605bb2",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18dd",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 6.5 / 39",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "_id": "5df780ec603399b430e7b249",
          "is_default": false,
          "is_required": true,
          "label": "Δικολορ",
          "sort_order": 0,
          "value": "#363030|#cd1bce",
          "value_data": null
        }
      }
    ],
  },
  {
    "_id": "5df7812f136d32086e605bc3",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18e3",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 9.5 / 42.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "label": "Μονοκολορ",
          "sort_order": 0,
          "value": "",
          "_id": "5df780dc603399b430e7b248"
        }
      }
    ],
  },
  {
    "_id": "5df7812f136d32086e605bcd",
    "options": [
      {
        "option": {
          "_id": "5ce3f95d35ad1e0999ee18db",
          "sort_order": 0,
          "display_name": "Μέγεθος (USA / EU)",
          "type": "text",
          "display_style": "dropdown"
        },
        "value": {
          "_id": "5ce3f95d35ad1e0999ee18e6",
          "is_default": false,
          "is_required": true,
          "sort_order": 0,
          "value": "",
          "label": "No 11 / 44.5",
          "option_id": "5ce3f95d35ad1e0999ee18db",
          "__v": 0
        }
      },
      {
        "option": {
          "_id": "5df780dc603399b430e7b247",
          "display_name": "swatch",
          "display_style": "swatch",
          "sort_order": 0,
          "type": "swatch"
        },
        "value": {
          "_id": "5df780ec603399b430e7b249",
          "is_default": false,
          "is_required": true,
          "label": "Δικολορ",
          "sort_order": 0,
          "value": "#363030|#cd1bce",
          "value_data": null
        }
      }
    ]
  }
]

const result = options.filter(f => f.values.some(s=> variants.some(v1 => v1.options.some(v2 => v2.value.value == s.value))));

console.log(result);

答案 1 :(得分:0)

老实说,这种数据结构需要重新处理-它使0有意义的ID有意义,并且ID在那么多的地方被复制,这很快就会使人感到困惑。

但是我认为我已经设法对其进行了排序。首先,您要过滤选项值以匹配变体,然后将变体过滤为其选项并检查ID的匹配。功能位于底部。我使用JSON技巧来深度克隆对象,这样就不会碰到原始对象。

const options = [
  {
    _id: "5ce3f95d35ad1e0999ee18db",
    sort_order: 0,
    values: [
      {
        _id: "5ce3f95d35ad1e0999ee18dc",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 6 / 38",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18dd",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 6.5 / 39",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18de",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 7 / 39.5",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18df",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 7.5 / 40",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e0",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 8 / 41",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e1",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 8.5 / 41.5",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e2",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 9 / 42",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e3",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 9.5 / 42.5",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e4",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 10 / 43",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e5",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 10.5 / 44",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e6",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 11 / 44.5",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e7",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 11.5 / 45",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e8",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 12 / 46",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18e9",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 12.5 / 46.5",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      },
      {
        _id: "5ce3f95d35ad1e0999ee18ea",
        is_default: false,
        is_required: true,
        sort_order: 0,
        value: "",
        label: "No 13 / 47",
        option_id: "5ce3f95d35ad1e0999ee18db",
        __v: 0
      }
    ],
    name: "ΥΠΟΔΥΣΗ | USA / EU ΜΕΓΕΘΗ 6/38 - 13/47",
    display_name: "Μέγεθος (USA / EU)",
    type: "text",
    display_style: "dropdown",
    __v: 0
  },
  {
    _id: "5df780dc603399b430e7b247",
    display_name: "swatch",
    display_style: "swatch",
    is_required: true,
    name: "Χρωματα",
    option_id: "",
    option_set_id: "",
    sort_order: 0,
    type: "swatch",
    values: [
      {
        label: "Μονοκολορ",
        sort_order: 0,
        value: "",
        _id: "5df780dc603399b430e7b248"
      },
      {
        _id: "5df780ec603399b430e7b249",
        is_default: false,
        is_required: true,
        label: "Δικολορ",
        sort_order: 0,
        value: "#363030|#cd1bce",
        value_data: null
      },
      {
        _id: "5df780f7603399b430e7b24a",
        is_default: false,
        is_required: true,
        label: "Τρικολορ",
        sort_order: 0,
        value: "#33cfb0|#308464|#819bca",
        value_data: null
      }
    ]
  }
];

const variants = [
  {
    _id: "5df7812f136d32086e605bae",
    options: [
      {
        option: {
          _id: "5ce3f95d35ad1e0999ee18db",
          sort_order: 0,
          display_name: "Μέγεθος (USA / EU)",
          type: "text",
          display_style: "dropdown"
        },
        value: {
          _id: "5ce3f95d35ad1e0999ee18dc",
          is_default: false,
          is_required: true,
          sort_order: 0,
          value: "",
          label: "No 6 / 38",
          option_id: "5ce3f95d35ad1e0999ee18db",
          __v: 0
        }
      },
      {
        option: {
          _id: "5df780dc603399b430e7b247",
          display_name: "swatch",
          display_style: "swatch",
          sort_order: 0,
          type: "swatch"
        },
        value: {
          label: "Μονοκολορ",
          sort_order: 0,
          value: "",
          _id: "5df780dc603399b430e7b248"
        }
      }
    ]
  },
  {
    _id: "5df7812f136d32086e605bb2",
    options: [
      {
        option: {
          _id: "5ce3f95d35ad1e0999ee18db",
          sort_order: 0,
          display_name: "Μέγεθος (USA / EU)",
          type: "text",
          display_style: "dropdown"
        },
        value: {
          _id: "5ce3f95d35ad1e0999ee18dd",
          is_default: false,
          is_required: true,
          sort_order: 0,
          value: "",
          label: "No 6.5 / 39",
          option_id: "5ce3f95d35ad1e0999ee18db",
          __v: 0
        }
      },
      {
        option: {
          _id: "5df780dc603399b430e7b247",
          display_name: "swatch",
          display_style: "swatch",
          sort_order: 0,
          type: "swatch"
        },
        value: {
          _id: "5df780ec603399b430e7b249",
          is_default: false,
          is_required: true,
          label: "Δικολορ",
          sort_order: 0,
          value: "#363030|#cd1bce",
          value_data: null
        }
      }
    ]
  },
  {
    _id: "5df7812f136d32086e605bc3",
    options: [
      {
        option: {
          _id: "5ce3f95d35ad1e0999ee18db",
          sort_order: 0,
          display_name: "Μέγεθος (USA / EU)",
          type: "text",
          display_style: "dropdown"
        },
        value: {
          _id: "5ce3f95d35ad1e0999ee18e3",
          is_default: false,
          is_required: true,
          sort_order: 0,
          value: "",
          label: "No 9.5 / 42.5",
          option_id: "5ce3f95d35ad1e0999ee18db",
          __v: 0
        }
      },
      {
        option: {
          _id: "5df780dc603399b430e7b247",
          display_name: "swatch",
          display_style: "swatch",
          sort_order: 0,
          type: "swatch"
        },
        value: {
          label: "Μονοκολορ",
          sort_order: 0,
          value: "",
          _id: "5df780dc603399b430e7b248"
        }
      }
    ]
  },
  {
    _id: "5df7812f136d32086e605bcd",
    options: [
      {
        option: {
          _id: "5ce3f95d35ad1e0999ee18db",
          sort_order: 0,
          display_name: "Μέγεθος (USA / EU)",
          type: "text",
          display_style: "dropdown"
        },
        value: {
          _id: "5ce3f95d35ad1e0999ee18e6",
          is_default: false,
          is_required: true,
          sort_order: 0,
          value: "",
          label: "No 11 / 44.5",
          option_id: "5ce3f95d35ad1e0999ee18db",
          __v: 0
        }
      },
      {
        option: {
          _id: "5df780dc603399b430e7b247",
          display_name: "swatch",
          display_style: "swatch",
          sort_order: 0,
          type: "swatch"
        },
        value: {
          _id: "5df780ec603399b430e7b249",
          is_default: false,
          is_required: true,
          label: "Δικολορ",
          sort_order: 0,
          value: "#363030|#cd1bce",
          value_data: null
        }
      }
    ]
  }
];

const tmp = options.map(option => {
  let newEle = JSON.parse(JSON.stringify(option));
  let newValues = option.values.filter(value => {
    if (
      variants.filter(
        vari =>
          vari.options.filter(opt => opt.value._id === value._id).length >
          0
      ).length > 0
    ) {
      return true;
    }
    return false;
  });
  newEle.values = newValues;
  return newEle;
});

console.log(tmp);