javascript sort method and some other bonuses
- Christina Williams
- Apr 27, 2020
- 1 min read
.then(checklists => {
$('#checklist_container').html('')
// console.log(checklists)
checklists.sort(function(a, b) {
var itemA = a.item.toUpperCase(); // ignore upper and lowercase
var itemB = b.item.toUpperCase(); // ignore upper and lowercase
if (itemA < itemB) {
return -1;
}
if (itemA > itemB) {
return 1;
}
// items must be equal
return 0;
});
console.log(checklists)
//Added this part to display the sorted data -
// iteration
// for each(variable in object) object for which properties are iterated
checklists.forEach(checklist => {
//statement
let newChecklist = new Checklist(checklist)
let checklistHtml = newChecklist.formatChecklist()
//Inject the HTML to the body of the page using append
$('#checklist_container').append(checklistHtml)
})
})
})
}
```
**When are good opportunities to use `console.log()` and `debugger` when coding in JS? How are they different?**
**console.log method** -- will allow you to check your work to make sure the code is defined. The console log sends a message to the console and tests the purpose of what you are asking about.
**The debugger method** stops the code execution of the Javascript where you place debugger; in your code. It acts the same as the breakpoint method in the javascript console.
You can see my entire project on Github [https://github.com/ChristinaXT/BabyGuide_JS](http://)
LEARN. LOVE. CODE.




Comments