我得到一个随机键值对,我可以将它分配给一个数组吗?
当我像这样分配它时,它在这里会出现问题,arr[50] = 'abc'
它会自动创建多达 50 个的键,例如,arr[0]
等等。arr[1]
arr[2]
我想要一个这样的数组arr[50=>'abc','40'=>'pqr','53'=>'lmn']
我这里有
if(typeof(feedArr.latestRating) == 'object'){
jQuery.each(feedArr.latestRating,function(key,val){alert('key::'+key);
if(key in newRatingArr){
//delete the key if already exists
newRatingArr.splice(key,1);
}else{
//insert the key,value
newRatingArr[key] = val; //here is the problem occurs when key is 50 it automatically creates the indexes in the array upto 50 which i dont want
// alert('Key between::'+key);
// alert('Value between::'+newRatingArr[key]);
//newRatingArr.splice(key,0,val);
}
//alert(key);
emptyRate = 0;
});
}else{
emptyRate = 1;
}
我可以在这里做什么?请告诉我。