Skip to content
Advertisement

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 “valid” means “only has base64 chars in it” then check

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 like this?

How can I prevent refresh of page when button inside form is clicked?

I have an issue while using buttons inside form. I want that button to call function. It does, but with unwanted result that it refresh the page. My simple code goes like this On clicking the button, the function gets called with page refreshed, which resets all my previous request which affects the current page which was result of the

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

Advertisement