Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get the middle character js

function getMiddle(s)
{
  var position;
  var length;

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

  return s.substring(position, position + length)
}
 
PREVIOUS NEXT
Tagged: #middle #character #js
ADD COMMENT
Topic
Name
8+5 =