Javascript Data Type How to - UpperCase certain char-index in a string








Question

We would like to know how to upperCase certain char-index in a string.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--   w ww. j  a  va2  s.c om-->
var str = 'post'; 
var arr =[0,2]; 
str = str.split("");
for(i = 0; i < arr.length; i++){
  str[arr[i]]=str[arr[i]].toUpperCase();
}
str = str.join('');
document.writeln(str);

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: