+ Start a Discussion
praveen kumar 267praveen kumar 267 

Please help me on java script

i got varible like this  var k=[text1~text2~text3,text11~text22~text33,text111~text222~text332];   i want split below like this plz any one can help out this   var name1=[text1,text11,text111]; var name2=[text22,text22,text222]; var name3=[text33,text33,text333];
Rahul SharmaRahul Sharma
What is your criteria to split?

[val11, val21, val31, val12, val22, val32, val13, val23, val33 ]
Do you have to split it like extract data in seperate variable or list based on the index?
praveen kumar 267praveen kumar 267
seperate varible having list of related data
praveen kumar 267praveen kumar 267
var name1=[text1,text11,text111]; first string,first elements
var name2=[text22,text22,text222]; second string second eleents
var name3=[text33,text33,text333];Third sting thirdelemts
Rahul SharmaRahul Sharma
Its not clear what you are intending to do, would you mind elaborating furthur?
praveen kumar 267praveen kumar 267
var k=[Ramesh~22~Hyderbad,Suresh~34~Bangalore,Rakesh~36~pune];

i want split below like this plz any one can help out this

var empname contains list of (Ramesh,Suresh,Rakesh)
var empno   contains list of (22,34,36)
var location contains list of (Hyderbad,Bangalore,pune)
praveen kumar 267praveen kumar 267
plz check the data ,you may get clear picture
Rahul SharmaRahul Sharma
Try the following:
// variable to collect the records
var finalArray = [];

var k = "text1~text2~text3,text11~text22~text33,text111~text222~text332";

var arrSplitLevel1 = k.split(",");

// iterate the array splitted by ,
for(var i = 0; i < arrSplitLevel1.length; i++) {

    var arrSplitLevel2 = arrSplitLevel1[i].split("~");
    var listOfValues = [];

    // iterate the array splitted by ~
    for(var j = 0; j < arrSplitLevel2.length; j++) {
        // collect the inner values

    // create array of an object with row count and values
        key: i,
        value: listOfValues

// verify the result

for(var i = 0; i < finalArray.length; i++) {
    alert(finalArray[i].key + " : " + finalArray[i].value);

Amit Chaudhary 8Amit Chaudhary 8
Hi Parveen,

I hope your issue is resolved in below post

Please try below code:-
var string str0=k.spilt(',');
var string[] str= k.spilt('~');
var EmpName=str[i]
var EmpNo=str[i]
var location=str[i]

Please let us know if your issue is resolved or you need more help.

Amit Chaudhary