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 :: can we find lenght of an object 
Javascript :: javascript string array sort alphabetically 
Javascript :: NextJS PWA gitignore 
Javascript :: typescript css variables 
Javascript :: ... array operator javascript 
Javascript :: adding binary numbers in javascript 
Javascript :: react image compression 
Javascript :: scrollheight jquery 
Javascript :: express bodyparser deprecated 
Javascript :: ionic angular change page route 
Javascript :: We often use anonymous functions as arguments of other functions. For example: 
Javascript :: sequelize.org findById 
Javascript :: redirect with react router v6 
Javascript :: mui how to set background in theme 
Javascript :: device width js 
Javascript :: js dynamicly add script 
Javascript :: expressjs swagger yaml 
Javascript :: how to reverse loop in javascript 
Javascript :: javascript every other element in array 
Javascript :: javascript filter unique 
Javascript :: javascript check if string is number 
Javascript :: laravel csrf token ajax post 
Javascript :: laravel query json 
Javascript :: how to check if browser tab is active javascript 
Javascript :: javascript for...of index 
Javascript :: test undefined js 
Javascript :: socket io client 
Javascript :: react native position text in center of view 
Javascript :: javascript sort array strings alphabetically 
Javascript :: javascript convert in a string the items of an array 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =