Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get middle of string js

const getMiddle = s => {
  let indexStart;
  let indexEnd;
  if (s.length % 2 > 0) {
    indexStart = Math.floor(s.length / 2);
    indexEnd = indexStart + 1;
  } else {
    indexStart = (s.length / 2) - 1;
    indexEnd = indexStart + 2;
  }
  return s.substring(indexStart, indexEnd);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: (node:63208) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead 
Javascript :: printf javasscript 
Javascript :: javascript remove a specific item from an array 
Javascript :: jquery checkbox checked or not 
Javascript :: javascript date minus minutes 
Javascript :: check if item exists in localstorage javascript 
Javascript :: python object to json 
Javascript :: pagination jsonplaceholder 
Javascript :: javascript fill array with range 
Javascript :: first letter capital in javascript 
Javascript :: asp.net core 3.1 convert system.string[] to javascript 
Javascript :: convert csv to json powershell code 
Javascript :: implement the remove property function 
Javascript :: set element position js 
Javascript :: remove time from date javascript 
Javascript :: How to access the request body when POSTing using Node.js and Express 
Javascript :: mongodb filter array 
Javascript :: how to tell c++ a function exists before calling 
Javascript :: How to fix CSS & JS not loading issue in cPanel laravel 
Javascript :: number validation in javascript 
Javascript :: image base64 to file javascript 
Javascript :: how to check if a message has an attachment discord js 
Javascript :: detect two strings are anagram of each other in JavaScript 
Javascript :: last element of an array javascript 
Javascript :: javascript replace last character 
Javascript :: for each python json 
Javascript :: javascript remove event listener 
Javascript :: js docstring example 
Javascript :: how to wait until a variable is set javascript 
Javascript :: js background 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =