javascript - Why an object key's first value is treated as a string - AngularJs -
i have object named "param" , has key named "item[]". values of item[] inserted dynamically.
problem when "item[]" has single value, treats value string , not first index of array.
example :
item[]="123";
but when has multiple values treats array desired, example-
item[] = ["123","456"];
i want single value index of array
item[] = ["123"]
how ?
p.s. - object created querystring parameters http://example.com/def?item[]=123&item[]=456, when extract querystring, returns these parameters keys of object
i extracting querystring in way(javascript)-
var param = $location.search(); console.log('param'); console.log(param);//returns object{item[]=[2]} in console
this because variablename[]
not javascript syntax.
since not recognise [], part of name if not throw error.
to create array, have 2 possibilities :
//contsructor var ar = new array(); //empty array //literal var ar = []; //same above var ar = [0,1,2,3]; //array of length 4 var ar = new array(4); //empty array of length 4
to access or set it
var ar[0] = "value"
Comments
Post a Comment