Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过从阵列中创建单独的列表,创建具有不同材质类型的单独材质列表_Javascript_Google Apps Script - Fatal编程技术网

Javascript 通过从阵列中创建单独的列表,创建具有不同材质类型的单独材质列表

Javascript 通过从阵列中创建单独的列表,创建具有不同材质类型的单独材质列表,javascript,google-apps-script,Javascript,Google Apps Script,我从下面使用的变量“exactSizedTypesDetected”中获得了一些材质类型,这是一个包含其他数组的数组(材质名称位于单独的数组中)。变量“exactSizedMaterialsData”中有一个材质列表,其形式与包含材质数组的数组相同。我的目标是根据材质类型将材质分离,并将它们存储在单独的变量中,因此我使用exacSizedList(1-100)创建了名称为的变量。我想要检测材质所属的材质类型的标准是,它检查数组中的第二个值,并匹配我使用“forEach(function(a){i

我从下面使用的变量“exactSizedTypesDetected”中获得了一些材质类型,这是一个包含其他数组的数组(材质名称位于单独的数组中)。变量“exactSizedMaterialsData”中有一个材质列表,其形式与包含材质数组的数组相同。我的目标是根据材质类型将材质分离,并将它们存储在单独的变量中,因此我使用exacSizedList(1-100)创建了名称为的变量。我想要检测材质所属的材质类型的标准是,它检查数组中的第二个值,并匹配我使用“forEach(function(a){if(a[1]==exactSizedTypesDetected[I-1])”实现的值

下面是我使用的代码,但当我使用logger.log()时,它对我不起作用。我的目标只是想自动创建包含材料类型的单独列表,即每个材料类型的单个列表,并自动保存为单独的数组变量,而无需我手动执行

提前谢谢你的帮助

function seperateExactSized() {
      // create variables
      var exacSizedList1,exacSizedList2,exacSizedList3,exacSizedList4,exacSizedList5,
          exacSizedList6,exacSizedList7,exacSizedList8,exacSizedList9,exacSizedList10,
          exacSizedList11,exacSizedList12,exacSizedList13,exacSizedList14,exacSizedList15,
          exacSizedList16,exacSizedList17,exacSizedList18,exacSizedList19,exacSizedList10,
          exacSizedList21,exacSizedList22,exacSizedList23,exacSizedList24,exacSizedList25,
          exacSizedList26,exacSizedList27,exacSizedList28,exacSizedList29,exacSizedList30,
          exacSizedList31,exacSizedList32,exacSizedList33,exacSizedList34,exacSizedList35,
          exacSizedList36,exacSizedList37,exacSizedList38,exacSizedList39,exacSizedList40,
          exacSizedList41,exacSizedList42,exacSizedList43,exacSizedList44,exacSizedList45,
          exacSizedList46,exacSizedList47,exacSizedList48,exacSizedList49,exacSizedList50,
          exacSizedList51,exacSizedList52,exacSizedList53,exacSizedList54,exacSizedList55,
          exacSizedList56,exacSizedList57,exacSizedList58,exacSizedList59,exacSizedList60,
          exacSizedList61,exacSizedList62,exacSizedList63,exacSizedList64,exacSizedList65,
          exacSizedList66,exacSizedList67,exacSizedList68,exacSizedList69,exacSizedList70,
          exacSizedList71,exacSizedList72,exacSizedList73,exacSizedList74,exacSizedList75,
          exacSizedList76,exacSizedList77,exacSizedList78,exacSizedList79,exacSizedList80,
          exacSizedList81,exacSizedList82,exacSizedList83,exacSizedList84,exacSizedList85,
          exacSizedList86,exacSizedList87,exacSizedList88,exacSizedList89,exacSizedList90,
          exacSizedList91,exacSizedList92,exacSizedList93,exacSizedList94,exacSizedList95,
          exacSizedList96,exacSizedList97,exacSizedList98,exacSizedList99,exacSizedList100 =[];

      // set variables dynamically
      for(var i=1; i<=100; i++) {
        eval("exacSizedList"+[i] + " = " + i);
        eval("exacSizedList"+[i-1] + ".push(a)");
        exactSizedMaterialsData.forEach(function(a) { if (a[1] ==exactSizedTypesDetected[i-1])  
          eval("exacSizedList"+[i] + ".push(a)"); });
        Logger.log(eval("exacSizedList"+[i] + ".push(a)"));
        Logger.log(eval("exacSizedList"+[i] ));
       }
      }
function separateExactSize(){
//创建变量
变量exacSizedList1,exacSizedList2,exacSizedList3,exacSizedList4,exacSizedList5,
exacSizedList6,exacSizedList7,exacSizedList8,exacSizedList9,exacSizedList10,
exacSizedList11,exacSizedList12,exacSizedList13,exacSizedList14,exacSizedList15,
exacSizedList16、exacSizedList17、exacSizedList18、exacSizedList19、exacSizedList10、,
exacSizedList21,exacSizedList22,exacSizedList23,exacSizedList24,exacSizedList25,
exacSizedList26、exacSizedList27、exacSizedList28、exacSizedList29、exacSizedList30、,
exacSizedList31、exacSizedList32、exacSizedList33、exacSizedList34、exacSizedList35、,
exacSizedList36、exacSizedList37、exacSizedList38、exacSizedList39、exacSizedList40、,
exacSizedList41、exacSizedList42、exacSizedList43、exacSizedList44、exacSizedList45、,
exacSizedList46、exacSizedList47、exacSizedList48、exacSizedList49、exacSizedList50、,
exacSizedList51、exacSizedList52、exacSizedList53、exacSizedList54、exacSizedList55、,
exacSizedList56、exacSizedList57、exacSizedList58、exacSizedList59、exacSizedList60、,
exacSizedList61、exacSizedList62、exacSizedList63、exacSizedList64、exacSizedList65、,
exacSizedList66、exacSizedList67、exacSizedList68、exacSizedList69、exacSizedList70、,
exacSizedList71、exacSizedList72、exacSizedList73、exacSizedList74、exacSizedList75、,
exacSizedList76、exacSizedList77、exacSizedList78、exacSizedList79、exacSizedList80、,
exacSizedList81、exacSizedList82、exacSizedList83、exacSizedList84、exacSizedList85、,
exacSizedList86、exacSizedList87、exacSizedList88、exacSizedList89、exacSizedList90、,
exacSizedList91、exacSizedList92、exacSizedList93、exacSizedList94、exacSizedList95、,
exacSizedList96、exacSizedList97、exacSizedList98、exacSizedList99、exacSizedList100=[];
//动态设置变量

对于(var i=1;i函数有许多问题。例如,exactSizedTypesDetected&exactSizedMaterialsData定义在哪里?我在forEach函数中未定义。对于要执行“a”的评估需要定义,以及为什么在forEach函数外部和forEach函数内部执行此操作?如果执行第一次求值,exacSizedListi将变为整数而不是数组。我假设ExactSizedTypesDetect有100个值,但如果exactSizedMaterialsData中没有匹配值,则子数组将为空。因此,最终您可以可能有非对称数组。您将无法在Google工作表中使用setValues()

我不确定这是否符合你的意图,但我会这样做

function seperateExactSized() {
  try {
    var exacSizedList = [];
    for( var i=0; i<100; i++ ) {
      exacSizedList.push([]);
    }
    for( var i=0; i<exactSizedMaterialsData.length; i++ ) {
      for( var j=0; j<100; j++ ) {
        // Where are exactSizedTypesDetected & exactSizedMaterialsData defined?
        if( exactSizedTypesDetected[j] === exactSizedMaterialsData[i][1] ) {
          exacSizedList[j].push(exactSizedMaterialsData[i]);
          break;
        }
      }
    }
  }
  catch(err) {
    Logger.log(err);
  }
}
function separateExactSize(){
试一试{
var exacSizedList=[];

对于(var i=0;我认为您需要使用带键的对象将无法维护的噩梦更改为更简单的版本。
const exactSizes={};
这种方法可以让您拥有任意数量的列表。在循环中,您只需检查该键是否已初始化:
if(!exactSizes[key])exactSizes[key]=[];
然后可以将适当的元素添加到该键中。(请注意,当前代码只初始化了您声明的最后一个变量。)