2

I have any array and I want to first sort it by filenames alphabetically then output the result into the table.

I have created the array successfully but don't know how to sort and output the result into the table. My current code doesn't output anything into table but console.log shows data of array! hope some one help me fix this problems.Thanks

error on f12:JSON.parse: unexpected character

This is how I create the array:

files.push({ url: this.gsx$url.$t, filename: this.gsx$name.$t });

array structure in console.log output:

Object { url="http://someurl.com", filename="new file"},.......

javascript function:

function displayArray(files){ 
alert(files.length);
console.log(files);


var txt = files;

var files = $.parseJSON( txt ).files;

var $table = $( "<table></table>" );

for ( var i = 0; i < files.length; i++ ) {
    var emp = files[i];
    var $line = $( "<tr></tr>" );
    $line.append( $( "<td></td>" ).html( emp.url ) );
    $line.append( $( "<td></td>" ).html( emp.filename ) );
    $table.append( $line );
}

$table.appendTo(document.body);


};
dsh
  • 12,037
  • 3
  • 33
  • 51
user1788736
  • 2,727
  • 20
  • 66
  • 110

0 Answers0