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);
}
>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))