function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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
        listOfValues.push(arrSplitLevel2[j]);
    }

    // create array of an object with row count and values
    finalArray.push({
        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
https://developer.salesforce.com/forums/?id=906F0000000BQhtIAG

Please try below code:-
var string str0=k.spilt(',');
for(j=0;j<str0.size();j++){
var string[] str= k.spilt('~');
for(i=0;i<string.length();i+3){
var EmpName=str[i]
}
for(i=1;i<string.length();i+3){
var EmpNo=str[i]
}
for(i=2;i<string.length();i+3){
var location=str[i]
}
}

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

Thanks,
Amit Chaudhary