Question: I want to replace second space occurrence of the sentence with a br.

I have tried this but it is deleting the rest.

```
var title = "My Title Needs Brace".split(" ").slice(0, 2).join(" ");

```

Answer: 
Try the following:

```js
var title = "My Title Needs Brace".split(" ");

title.forEach(function(item, i, title){
  if(i==1)
    title[i] += "<br/>";
  else
  title[i] += ' ';
})

console.log(title.join(''));
```
> 
> I want to replace second space occurrence of the sentence with a br.
> 
> 
> 

The simple way to do that is to add `"<br/>"` to the second element.

Here is the Code.

```js
$(document).ready(function(){
  var title = "My Title Needs Brace".split(" ");
  title[1] = title[1]+"<br/>";
  var newstr = title.join(" ");
  $("#textd").html(newstr);
});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="textd">
</div>
```