On the Optimization of if else and switch

let url = location.search
var idbox = {}
if (url === "?news") {
  idbox = {id: 43}
} else if (url === "?character") {
  idbox = {id: 39631}
} else if (url === "?hotspot") {
  idbox = {id: 8928}
} else if (url === "?relation") {
  idbox = {id: 7972}
} else if (url === "?manage") {
  idbox = {id: 444}
} else if (url === "?scholarship") {
  idbox = {id: 3380}
}
  • how to optimize the above code, use map?
May.01,2021

let config = { '?news':{id:43}, '?character':{id: 39631}, ...}
let url = location.search;
let idbox = config[url];

use switch case

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b5cd-2c27d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b5cd-2c27d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?