Trying to refactor and make use of the map object

Viewed 70
const typesMap = new Map([
  ['imp', '/imported'],
  ['branded', '/brands'],
  ['imp,branded', '/imported-brands'],
  ['branded,imp', '/imported-brands'],
  ['local', '/local'],
])

a person here refactored the if else statement likewise

typesMap.get('branded');

gets the /brands

but when I try to do it to get object from an array of objects in a similar pattern

const typesMap = new Map([
  ['imp', (0,1), (1,1)],
  ['branded', (0,2)]
])

I am using these numbers with the splice array method but typesMap.get returns 1 for 'imp' and 2 for 'branded'. I don't know what this method is called to google and study it also to understand in what manner this works

 const menu = [{
    id: 0,
    menu: "Cart",
    urlLink: "/cart"
  },
  {
    id: 1,
    menu: "Imported",
    urlLink: "/imported",
  },
  {
    id: 2,
    menu: "Branded",
    urlLink: "/branded",
  }]

I am trying to splice the menu as per the user's preference

 useEffect(()=>{
    menu.splice(typesMap.get(localStorage.getItem('types')));
  }, [menus]);
0 Answers
Related