What is $.each doing in this function, and how can I rewrite it to work without using jQuery -


i learning javascript, , encountered function on website. seems use jquery, don't have experience with. understand function except lines $.each.

can me rewrite function without $.each? don't understand means, after reading jquery documentation. referring to, , how can rewrite function work without jquery ?

arraysort = function(array, sortfunc){               var tmp = [];               var asorted=[];               var osorted={};                (var k in array) {                 if (array.hasownproperty(k))                      tmp.push({key: k, value:  array[k]});               }                tmp.sort(function(o1, o2) {                     return sortfunc(o1.value, o2.value);               });                                     if(object.prototype.tostring.call(array) === '[object array]'){                   $.each(tmp, function(index, value){                       asorted.push(value.value);                   });                   return asorted;                                    }                if(object.prototype.tostring.call(array) === '[object object]'){                   $.each(tmp, function(index, value){                       osorted[value.key]=value.value;                   });                                        return osorted;               }                     }; 

you can update code from

$.each(tmp, function(index, value){     asorted.push(value.value); }); 

to

for (var = 0; < tmp.length; i++) {      asorted.push(tmp[i].value); } 

similarly, can achieve same other $.each updating following

for (var = 0; < tmp.length; i++) {     var obj = tmp[i];     osorted[obj.key] = obj.value; };       

note: tmp sorted. can return tmp , iterate on , tmp.value or tmp.key.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -