Monday, April 16, 2012

how to save an array in an object at runtime in javascript

i want to save an array in an object in runtime through a loop:
for example i take an input in an array inp=[2,7,20,15,19] and i want to save it in an obj={0:2,1:7,2:20,3:15,4:19} but at run time such that i have a



for(i=0;i<inp.length;i++) 
{ save each element of array into the respective object element }


the problem is that i have to save arrays of different lengths that i am taking as input from user.i am also sorting the object afterwards and returning the indices in another array in my code. i am stuck only at how to save an array in an object during runtime.i searched alot for a clue to get started but i could not find anything.



thanks in advance





No comments:

Post a Comment