0

My first post here and ive been looking for a solution everywhere but gonna give it a go and ask instead because im out of ideas.

So i have this string that i get from an Mainframe API (1100000110000011000001100000110) which represents the days of a month, in this case AUG 2020. The 1´s represents Saturdays, Sundays and other holidays if there are any. 0´s are working day.

What i need to do is to check if current date (today) is equal to 1 or 0 corresponding to this string.

So for example if i where to check if day 31 of this month is a 0 or a 1.

Hope you understand.

Christian
  • 27
  • 1
  • 5
  • 2
    So your question basically boils down to, “how can I access the x-th character in a string value” …? That should be quite easy to research. – CBroe Aug 31 '20 at 12:29

2 Answers2

3

You can try like below

const str = "1100000110000011000001100000110";

function getDayValue(dayNo) {
  const splittedValues = str.split("");
  return splittedValues[dayNo - 1];
}

console.log(getDayValue(31));
Sivakumar Tadisetti
  • 4,865
  • 7
  • 34
  • 56
  • 1
    You don't need to convert to an array, string characters can be accessed by index too, so simply `str[dayNo - 1] == '1'? 'weekend':'week'` – RobG Aug 31 '20 at 23:59
1

You can try this:

var str = "1100000110000011000001100000110";

function getDayAccordingToNumber(index){
    return str.split("")[index-1];
}
console.log(getDayAccordingToNumber(31));
Aman Kumayu
  • 381
  • 1
  • 9