English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
split()Metodo JavaScript String split()
separator Il metodo divide una stringa in un array di sottostringhe e restituisce un nuovo array.
Il parametro determina dove effettuare ogni divisione.separatorSe viene utilizzata una stringa vuota (""),
string.split(separatore, limit)
var str = 'Air Pollution is introduction of chemicals to the atmosphere.'; var arr = str.split(" ");Prova a vedere‹/›
Tutti i browser supportano completamente il metodo split():
Metodo | |||||
split() | È | È | È | È | È |
Parametro | Descrizione |
---|---|
separator | (Obbligatorio) Specificare un carattere o un'espressione regolare che indica il punto in cui ogni divisione deve avvenire |
limit | (opzionale) Un intero che specifica il numero di divisioni, i progetti dopo il limite di divisione non verranno inclusi nell'array |
Valore di ritorno: | che si verifica nella stringa fornitaseparatorArray di stringhe divise a ogni punto |
---|---|
Versione JavaScript: | ECMAScript 1 |
Ora stiamoarrLa variabile ha avuto un nuovo array, possiamo accedere a ciascun elemento utilizzando l'indice:
arr[0]; // Air arr[2]; // isProva a vedere‹/›
Usa "i" come separatore:
var str = 'Air Pollution is introduction of chemicals to the atmosphere.'; var arr = str.split("i");Prova a vedere‹/›
Dividi ogni carattere:
var str = 'Air Pollution is introduction of chemicals to the atmosphere.'; var arr = str.split("");Prova a vedere‹/›
Restituisci una quantità limitata di divisioni:
var str = 'Air Pollution is introduction of chemicals to the atmosphere.'; var arr = str.split(" ", 4);Prova a vedere‹/›