0

Following the the array where i want to get 1 element from every array from the object and create an new array.

Input array--

const categories = [
  {
    code: "noodle",
    ingredients: ["wheat_noodle", "maida_noodle", "rice_noodle"],
  },
  {
    code: "oil",
    ingredients: ["soyabeen_oil", "peenut_oil", "sunflower_oil"],
  },
  {
    code: "salt",
    ingredients: ["kosher_salt", "ground_salt", "table_salt"],
  },
  {
    code: "sauce",
    ingredients: ["soya_sauce", "chilli_sauce", "tommato_sauce"],
  },
]

Following is how i want my array output to be. Basically take every 1 element from each object and make combination.

[
  [ 'wheat_noodle', 'soyabeen_oil', 'kosher_salt', 'soya_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'kosher_salt', 'chilli_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'kosher_salt', 'tommato_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'ground_salt', 'soya_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'ground_salt', 'chilli_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'ground_salt', 'tommato_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'table_salt', 'soya_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'table_salt', 'chilli_sauce' ],
  [ 'wheat_noodle', 'soyabeen_oil', 'table_salt', 'tommato_sauce' ],
  [ 'wheat_noodle', 'peenut_oil', 'kosher_salt', 'soya_sauce' ],
  [ 'wheat_noodle', 'peenut_oil', 'kosher_salt', 'chilli_sauce' ],
  [ 'wheat_noodle', 'peenut_oil', 'kosher_salt', 'tommato_sauce' ],
  [ 'wheat_noodle', 'peenut_oil', 'ground_salt', 'soya_sauce' ],
  [ 'wheat_noodle', 'peenut_oil', 'ground_salt', 'chilli_sauce' ],
  [ 'wheat_noodle', 'peenut_oil', 'ground_salt', 'tommato_sauce' ],
  ...
]
Balkrushna
  • 41
  • 2
  • 9

0 Answers0