-4

I've this code :

$("input").keyup(function() {
  var data = this.value.split(" ");
  $('p').append(data.slice(0));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="search">
<p></p>

I want the first letter of this array to be capitalize, thanks for your help !

Milan Chheda
  • 8,159
  • 3
  • 20
  • 35
Corentin Branquet
  • 241
  • 1
  • 2
  • 11
  • `$('p').text($(this).val().split(" ").map(str => str && str[0].toUpperCase() + (str.length > 1 ? str.slice(1).toLowerCase() : '')).join(" "));` – Tushar Oct 16 '17 at 08:27

2 Answers2

2

Here you go:

data[0] = data[0].toUpperCase();

Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56
1

Use Javascript Prototype..

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}


var test = "hello";

console.log(test.capitalize())
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35
Amit Kumar
  • 5,888
  • 11
  • 47
  • 85