Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Thursday, April 23, 2020

Program to print numbers from 0 to 50 in JavaScript



  1. var printFiftyNumbers() {
  2. var text = "";
  3. var i;
  4. for(i=0; i <= 50; i++) {
  5. text += i + "<br>";
  6. }
  7. document.getElementById("demo").innerHTML = text;
  8. }

Convert Image to Base64 array in JavaScript

It is very easy to convert image to Base64 String in JavaScript. 

To convert you need jQuery library to your html.

Just pass the image to this below imageFileAsBase64(). Get the Base64 value for the image in imagebase64 variable.


  1. var imagebase64 = "";  
  2.   
  3. function imageFileAsBase64(element) {  
  4.     var file = element.files[0];  
  5.     var reader = new FileReader();  
  6.     reader.onloadend = function() {  
  7.         imagebase64 = reader.result;  
  8.     }  
  9.     reader.readAsDataURL(file);  
  10. }