Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

count of elements concatenated in apps script

I have a concatenated range of values. I am trying to get the number of elements concatenated by looping over the range B2:B to identify the count of elements if are 3.

The loop should check if there are 3 elements then push those values into an array, if encountered 1 element then should break out.

function test(){
   d1= SpreadsheetApp.getActiveSpreadsheet();
   var P_Details = d1.getSheetByName("test1");
   var P_range = P_Details.getRange("B2:B");
   var P_val = P_range.getValues();
   
   P_dump = [];
   for (var i in P_val){
     if(// (code here to split and count)=3){
         P_dump.push(P_val[i]);
     }
     else{ 
     break;
     }
   }
}


[![image of the range][1]][1]


  [1]: https://i.stack.imgur.com/1NfOp.jpg

|          | Concatenated values|
| -------- | -------------------|
|          | a-b-c              |
|          | a-d-e              |
|          | w-x-y              |
|          | d                  |
|          | d                  |
|          | e                  |

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this,

   P_dump = [];
   for (var i in P_val){
     if(P_val[i][0].split('-').length == 3){
         P_dump.push(P_val[i][0]);
     }
     else{ 
      break;
     }
   }
   console.log(P_dump);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading