Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple javascript split() working as intended? [duplicate]

fiddle: https://jsfiddle.net/jzhang172/4ntjykr0/

var x="pokemon,rykrkr";
x.split(",");
document.getElementById('ok').innerHTML=x[0];
<div id="ok"></div>

Isn't this supposed to show the whole word "pokemon" because I specified that it would split on comma?

like image 642
Snorlax Avatar asked Dec 12 '25 03:12

Snorlax


1 Answers

.split doesn't alter the original string, so you have to do it like this:

var x = "pokemon,rykrkr";
var splited = x.split(",");

document.getElementById('ok').innerHTML = splited[0];
<div id="ok"></div>
like image 88
The Process Avatar answered Dec 13 '25 15:12

The Process



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!