Okey ecco il mio codice con dettagli di ciò che ho cercato di fare:Get prima parola della stringa
var str = "Hello m|sss sss|mmm ss"
//Now i separate them by "|"
var str1 = str.split('|');
//Now i want to get the first word of every split-ed sting parts:
for (var i=0;i<codelines.length;i++)
{
//What to do here to get the first word of every spilt
}
Quindi, che cosa devo fare c'è: \ Quello che voglio ottenere è FirstWord [0] darà "Ciao" e FirstWord [1] darà "sss" e FirstWord [2] darà "mmm"
Non funziona: s http://jsbin.com/umeqi4/17 –
@SasukeKun Hai dimenticato una 's' in' firstWords' dopo l'* per * ciclo: http: // jsbin .com/umeqi4/19/ – ComFreek
Sì, sembra che 'String.prototype.substr()' sia leggermente più veloce: http://jsperf.com/get-first-word-of-string – Benj