Skip to content

Determine if string is in base64 using JavaScript

I’m using the window.atob(‘string’) function to decode a string from base64 to a string. Now I wonder, is there any way to check that ‘string’ is actually valid base64? I would like to be notified if the string is not base64 so I can perform a different action. Answer If “v…

Converts minutes into days, week, months and years

Let’s suppose I have a number which represents the minutes passed from the start time to now. I wan to create a function which returns the years, months, week and days corresponding to the minutes I am passing to that function. Here an example: What is the best way to achieve the result? Answer Maybe li…

JavaScript Number Split into individual digits

I am trying to solve a math problem where I take a number e.g. 45, or 111 and then split the number into separate digits e.g. 4 5 or 1 1 1. I will then save each number to a var to run a method on. Does anyone know how to split a number into individual digitals? For example I