[Solved] How could a viable transformation look like that does convert a product-name into a valid HTML id-attribute value? [closed]


You can try this-

const data = [
  "2-inch leg extension",
  "2' x 8' Overhead Garage Storage Rack",
  "4 Drawer Base Cabinet 16-1/2\"W x 35\"H x 22-1/2\"D",
  "24\" Long Tool Bar w/ Hooks  Accessory"
];

const res = data.map(str => str.replace(/[^a-z\d\-_]/ig, ''));

console.log(res);

If you need any prefix with the ID then add it like-

const prefix = 'Z';
const res = data.map(str => prefix + str.replace(/[^a-z\d\-_]/ig, ''));

solved How could a viable transformation look like that does convert a product-name into a valid HTML id-attribute value? [closed]