SOURCE

let unproductList = [
                    {
                        "name":"慢干54合成纸/60g格拉辛/水胶1",
                    },
                    {
                        "name":"慢干54合成纸/60g格拉辛/水胶2",
                    },
                    {
                        "name":"慢干54合成纸/60g格拉辛/水胶",
                    },{
                        "name":"慢干54合成纸/60g格拉辛/水胶1",
                    },
                    {
                        "name":"慢干54合成纸/60g格拉辛/水胶",
                    },
                    {
                        "name":"慢干54合成纸/60g格拉辛/水胶",
                    },{
                        "name":"慢干54合成纸/60g格拉辛/水胶",
                    },
                    {
                        "name":"慢干54合成纸/60g格拉辛/水胶1",
                    },
                    {
                        "name":"慢干54合成纸/60g格拉辛/水胶2",
                    }
                ]

function assignNumber(names) {
  const seen = new Map();
  const result = [];
  const color = [
                "#000000",
                "#FF0000",
                "#008000",
                "#FFA500",
                "#800080",
                "#FFC0CB",
                "#800000",
                "#FF00FF",
                "#008080",
                "#A52A2A",
                "#FF6347",
                "#9400D3"];

  const colorsAssigned = {};
  
  for (const name of names) {
    if (seen.has(name)) {
      result.push(seen.get(name));
    } else {
      let number = 0;
      while (colorsAssigned[number]) {
        number = String(parseInt(number) + 1).padStart(3, "0");
      }
      colorsAssigned[number] = color.shift();
      seen.set(name, colorsAssigned[number]);
      result.push(colorsAssigned[number]);
    }
  }
  
  return result;
}



const numbers = assignNumber(unproductList.map(x => x.name));
console.log(numbers); 
console 命令行工具 X clear

                    
>
console