Javascript: Sorting Parsed Json Within _.each Loop
var Bible = JSON.parse( fs.readFileSync(bible.json, 'utf8') ); _.each(Bible, function (b, Book) { return Book; }); This outputs each book name from the Bible (ex. Genesis, Exodus
Solution 1:
You cannot sort inside each
because that would be too late.
But you can sort before using _.each
:
varBible = JSON.parse( fs.readFileSync(bible.json, 'utf8') );
Bible.sort(); // sorts in place
_.each(Bible, function (b, Book) {
returnBook;
});
Or pass the sorted value as a parameter to each
:
varBible = JSON.parse( fs.readFileSync(bible.json, 'utf8') );
_.each(Bible.sort(), function (b, Book) {
returnBook;
});
Post a Comment for "Javascript: Sorting Parsed Json Within _.each Loop"