get array value from get method

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 12:05:00

问题


How to get separate values of array in javascript?

in one page:

var c=new Array(a); (eg: a={"1","2"}) window.location="my_details.html?"+ c + "_"; and in my_details.html :

my_details.htm:

var q=window.location.search;     
alert("qqqqqqqqqqqqq " + q);    
var arrayList = (q)? q.substring(1).split("_"):[];       
var list=new Array(arrayList);     
alert("dataaaaaaaaaaaa " +  decodeURIComponent(list)   + "llll " );  

But i am not able to get individual array value like list[0] etc
How to get it?

thanks
Sneha


回答1:


decodeURIComponent() will return you a String; you need to do something like:

var delim = ",",
    c = ["1", "2"];

window.location = "my_details.html?" + c.join(delim);

And then get it back out again:

var q = window.location.search,
    arrayList = (q)? q.substring(1).split("_"):[],       
    list = [arrayList];     
    arr = decodeURIComponent(list).split(delim);

This will use the value of delim as the delimiter to make the Array a String. We can then use the same delimiter to split the String back into an Array. You just need to make sure delim is available in the scope of the second piece of code.



来源:https://stackoverflow.com/questions/8559075/get-array-value-from-get-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!