-1
blocks.map((item) => {
    return item.SubCategory.map((subItem) => {
      return subItem.modal.map((modal) => {
        let Blocks = selectedBlock === item.Category;
        let SubBlocks = selectedSubBlock === subItem.id;

        if (SubBlocks && Blocks) {
          return bm.add(modal.id, {
            label: modal.label,
            content: modal.content,
          });
        }

        return null;
      });
    });
  });

How Can we Access modal Array Without Nesting it any Possibilities Like Using Lodash Object Methods to Access the Required Key get(val, 'val.val.val') is there any Option to do Like this in Array Methods

1 Answer 1

1

You are looking for Array.prototype.flat

let modals = ["modal1", "modal2", "modal3"];
let subitems = [modals, modals, modals];
let items = [subitems, subitems, subitems];
let blocks = [items, items, items];

let modals_only = blocks.flat(3);
console.log(modals_only) // Array(81) [ "modal1", "modal2", "modal3", ... ]

In your scenario, I would write

blocks.flat(3).map(block => {
    //...
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.