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

Extract first number

how can i extract the first number from this array?
The number is taken from the variable and then divided, from 0222 to [ 0, 2, 2, 2 ]
I need to check the first number, but I can’t.

thank you

var cellF9 = sh.getRange(9, 6, 1, 1).getValue();

  String(cellF9).split("").map(Number);
  function splitNum(num) {
    return String(num).split("").map(Number);
  }

  console.log(splitNum(cellF9));

  switch (cellF9[0]) {
    case 0:
      sh.getRange("F18").setValue("test");
      break;
    default:
      SpreadsheetApp.getUi().alert(".......", ".............", SpreadsheetApp.getUi().ButtonSet.OK);

  }

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 :

In switch (cellF9[0]) { you are indexing against the original string "0222". You can either do

switch (splitNum(cellF9[0])) {

or

const splittedNumber = splitNum(cellF9[0])
switch (splittedNumber) {

A solution without splitting it into an array:

const cell = '0222'
console.log(cell.charAt(0))
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