Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript how to get middle letters of a string

 function extractMiddle(str) {

        var position;
        var length;

        if(str.length % 2 == 1) {
            position = str.length / 2;
            length = 1;
        } else {
            position = str.length / 2 - 1;
            length = 2;
        }

        return str.substring(position, position + length)
    }

    console.log(extractMiddle("handbananna"));
Comment

PREVIOUS NEXT
Code Example
Javascript :: add tab to textarea 
Javascript :: isotope cdn 
Javascript :: how to check hover effect in js 
Javascript :: difference between let and var 
Javascript :: for each of object 
Javascript :: responsive calc height react native 
Javascript :: expressjs async await 
Javascript :: flutter build runner json serializable 
Javascript :: angular directive output 
Javascript :: encrypt decrypt javascript 
Javascript :: check css property jquery 
Javascript :: js generate random string of length 
Javascript :: js sort letters 
Javascript :: or inside if javascript 
Javascript :: how to format an integer with a comma in javascript 
Javascript :: if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1. 
Javascript :: maths 
Javascript :: axios how to get error response 
Javascript :: javascript hash string 
Javascript :: dot env react native 
Javascript :: buffer in javascript 
Javascript :: how to check if value is undefines if condition jquery 
Javascript :: javascript anagram 
Javascript :: node javascript foreach limit 
Javascript :: nodejs emit event from class 
Javascript :: suppress spaces in front and in the end of a string javascript 
Javascript :: string to jspn js 
Javascript :: get date in specific timezone 
Javascript :: how to check if checkbox is checked in jquery 
Javascript :: chartjs each dataset get colors 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =