jquery - Is it possible to set/change the value of every item in an array that does not use incremental values for item placement (0,1,2,etc...)? -


i have array in items stored using other elements' id values (not integers). upon clicking button want able change boolean values of each item in array 'false' in 1 swoop. i'm assuming can't done loop since i'm familiar loop using integer incrementation. there way change of these values @ once or need rethink this?

because didnt post how array looks assume structure. code reset boolean false:

var array = {     "id1":"foo",     "id2":"bar",     "id3":true,     "id4":1,     "id5":false, };  $.each(array,function(index,obj){     if(typeof obj === 'boolean' ) array[index] = false; });  console.log(array); 

here jsfiddle (check console log)

trick understand array in javascript object numeric keys. keys don't have numeric though, , can still access array using non-numeric key. example using array above, array["id1"] valid in javascript. equivalent of array.id1

update

the 'array' variable not array here object. please read @balusc's comment below details.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -