Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript function convert bytes into mb

function bytesToSize(bytes) {
  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
  if (bytes === 0) return 'n/a'
  const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10)
  if (i === 0) return `${bytes} ${sizes[i]})`
  return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`
}
Comment

byte to mb js

function formatBytes(a,b=2){if(0===a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return parseFloat((a/Math.pow(1024,d)).toFixed(c))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]}
Comment

js mb to bytes

function toBytes(size, type)
{
  const types = ["B", "KB", "MB", "GB", "TB"];

  const key = types.indexOf(type.toUpperCase())
  
  if (typeof key !== "boolean") {
      return  size * 1024 ** key;
  }
  return "invalid type: type must be GB/KB/MB etc.";
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: adding styling to element using javascript 
Javascript :: javascript tofixed is not a function 
Javascript :: how to display image in react js component 
Javascript :: javascript if value is a string function 
Javascript :: how to check if checkbox is checked in jquery 
Javascript :: appending an element to another element javascript 
Javascript :: check if isset variable js 
Javascript :: fetch Response object get content type 
Javascript :: image preview before upload jquery 
Javascript :: socket.io client send data node js server 
Javascript :: $q.platform.is.mobile 
Javascript :: electron how to setup preload.js 
Javascript :: jquery body remove class 
Javascript :: javascript get sub array 
Javascript :: reactjs cut part of string 
Javascript :: preloader 
Javascript :: how to send a request to a web server javascript 
Javascript :: js array includes 
Javascript :: run function then empty it 
Javascript :: mongodb mongoose update an element in an array of objects 
Javascript :: jquery check if all checkbox is not checked 
Javascript :: tsconfig 
Javascript :: formgroup is not property of form angular 
Javascript :: document queryselectorall and map javacript 
Javascript :: file name in react input 
Javascript :: functional component how to add to existing array react 
Javascript :: remove part of string javascript 
Javascript :: link to another page and achor react 
Javascript :: space in string using if in jquery 
Javascript :: at in js 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =