Javascript Object ksort()

Description

Javascript Object ksort()


function ksort(obj) {
  if (!obj || typeof (obj) != 'object') {
    return [];/*  w  w  w.  j av a  2s  .c o  m*/
  }

  var keys = [],
    values = [];
  for (var i in obj) {
    keys.push(i);
  }

  keys.sort();
  for (var i = 0; i < keys.length; i++) {
    values.push(obj[keys[i]]);
  }

  return values;
}



PreviousNext

Related