Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JScript Split Method 1

Status
Not open for further replies.

captedgar

Programmer
Dec 4, 2009
20
GB
Hi there

I'm trying to figure out what the following syntax for split means in the following line of the code

arrTest[0].split('/')[0]

what does ('/')[0] means in split('/')[0]?

please can anyone explain
 
Hi

captedgar said:
what does ('/')[0] means in split('/')[0]?
[tt]split('/')[/tt] - the [tt]split()[/tt] method splits the string in pieces separated by the given string or regular expression and returns the result as an array.
[tt][0][/tt] - refers to the element of the array at the position given by the index.

Give it a try in the FireBug Console :
Code:
[blue]>>> arrTest=['foo/bar/baz','something/else','some/more'][/blue]
[b][[/b] [red]"foo/bar/baz"[/red], [red]"something/else"[/red], [red]"some/more"[/red] [b]][/b]
[blue]>>> arrTest[0][/blue]
[red]"foo/bar/baz"[/red]
[blue]>>> arrTest[0].split('/')[/blue]
[b][[/b] [red]"foo"[/red], [red]"bar"[/red], [red]"baz"[/red] [b]][/b]
[blue]>>> arrTest[0].split('/')[0][/blue]
[red]"foo"[/red]

Feherke.
 
Its spliting the string at the slash character and returning the value of the first section that was split off.

In other words, for a string like: "This/is/a/string" it would put the word "This" in the array.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top