Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js get string byte size

// JavaScript
(new Blob(['20€'])).size;		// 5

// Node js
Buffer.from('20€').length;	// 5
Comment

javascript get string byte size

      getStringMemorySize = function( _string ) {
        "use strict";

        var codePoint
            , accum = 0
        ;

        for( var stringIndex = 0, endOfString = _string.length; stringIndex < endOfString; stringIndex++ ) {
            codePoint = _string.charCodeAt( stringIndex );

            if( codePoint < 0x100 ) {
                accum += 1;
                continue;
            }

            if( codePoint < 0x10000 ) {
                accum += 2;
                continue;
            }

            if( codePoint < 0x1000000 ) {
                accum += 3;
            } else {
                accum += 4;
            }
        }

        return accum * 2;
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: filtering in javascript 
Javascript :: javascript object array sum of values in object 
Javascript :: Add select option by using <a in AngularJS 
Javascript :: javascript slider 
Javascript :: axios.get Uncaught (in promise) TypeError: response.json is not a function 
Javascript :: get two types of date formate datepicker 
Javascript :: Material-ui snowflake icon 
Javascript :: angular keyframes % 
Javascript :: Resize Image Using HTML Canvas in JavaScript 
Javascript :: javascript read file 
Javascript :: movement of objects in javascript 
Javascript :: replaceAll vs replace vs split join 
Javascript :: href before onclick js 
Javascript :: adding data attributes to react-select 
Javascript :: yup test string async 
Javascript :: Javascript basic arrow function 
Javascript :: custom search filter in angular 8 
Javascript :: back button not working when modal open in react native 
Javascript :: python dictionary setdefault in javascript 
Javascript :: p5js no stroke 
Javascript :: vanilla js select by class 
Javascript :: dm discord.js 
Javascript :: base64 js vanilla 
Javascript :: key value pair array in javascript 
Javascript :: mongoose discriminator 
Javascript :: Nuxt Use Nginx as reverse Proxy 
Javascript :: createElement calls with JSX 
Javascript :: nodemon.json env 
Javascript :: js compare tow object values 
Javascript :: react hooks 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =