Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Split into multiple variables [duplicate]

Possible Duplicate:
Possible to assign to multiple variables from an array?

If in python i can do this

x = "Hi there and hello there"
v1, v2, v3, v4, v5 = x.split(" ")

but im not sure how to do it in javascript..

like image 878
Natsume Avatar asked Dec 12 '22 00:12

Natsume


1 Answers

You can turn it into an array by using javascript .split

For example

x = "Hi there and hello there";
var array = x.split(" ");

Then all your variables will be in the array like below

array[0]
array[1]
array[2]

You can show this using console.log or an alert like so.

console.log(array[0]);
alert(array[0]);

References

http://www.tizag.com/javascriptT/javascript-string-split.php

like image 50
Undefined Avatar answered Dec 15 '22 01:12

Undefined