库中的Javascript索引超出范围

库中的Javascript索引超出范围,javascript,Javascript,我正在尝试将一个Javascript库(名为该颜色)改编为Python 我对这段代码感到困惑: for(var i = 0; i < ntc.names.length; i++) { if(color == "#" + ntc.names[i][0]) return ["#" + ntc.names[i][0], ntc.names[i][1], true]; ndf1 = Math.pow(r - ntc.names[i][2], 2)

我正在尝试将一个Javascript库(名为该颜色)改编为Python

我对这段代码感到困惑:

for(var i = 0; i < ntc.names.length; i++)
    {
      if(color == "#" + ntc.names[i][0])
        return ["#" + ntc.names[i][0], ntc.names[i][1], true];

      ndf1 = Math.pow(r - ntc.names[i][2], 2) + Math.pow(g - ntc.names[i][3], 2) + Math.pow(b - ntc.names[i][4], 2);
      ndf2 = Math.pow(h - ntc.names[i][5], 2) + Math.pow(s - ntc.names[i][6], 2) + Math.pow(l - ntc.names[i][7], 2);
      ndf = ndf1 + ndf2 * 2;
      if(df < 0 || df > ndf)
      {
        df = ndf;
        cl = i;
      }
    }
这些电话是不是
ntc.names[i][2]
ntc.names[i][3]
<代码>ntc.名称[i][7]超出名称标识的范围


此代码是如何工作的?

看起来像是
ntc.names
数组在
init
方法中发生了更改:

  ntc.names[i].push(rgb[0], rgb[1], rgb[2], hsl[0], hsl[1], hsl[2]);

所以不,不是超出范围。

看看
init
方法……啊,谢谢,现在就知道了!谢谢,我没注意到
  ntc.names[i].push(rgb[0], rgb[1], rgb[2], hsl[0], hsl[1], hsl[2]);