Skip to content
Omni Academy
Search courses and lessons
Search
Courses
Backend Development
9
Databases
1
Frontend Development
5
Data Science
5
All courses →
Playground
HTML & CSS
JavaScript
TypeScript
Python
PHP
Ruby
Light
Dark
Auto
Sign in
Get started
All
Backend Development
Databases
Frontend Development
Data Science
Playground
Blog
HTML
JS
TS
PY
PHP
RB
← Courses
📄
JavaScript basics
Run as I type
Reset
▶
Run
Ctrl
↵
JS
JavaScript source code
// Everything you log appears in the pane on the right. const learners = [ { name: 'Aisha', score: 92 }, { name: 'Kenji', score: 78 }, { name: 'Lena', score: 85 }, { name: 'Sam', score: 61 }, ]; // Array methods chain, and each one returns a new array rather than // changing the one you gave it. const passed = learners .filter((l) => l.score >= 70) .sort((a, b) => b.score - a.score); console.log('Passed:', passed.map((l) => l.name)); const average = learners.reduce((sum, l) => sum + l.score, 0) / learners.length; console.log('Average:', average.toFixed(1)); // Destructuring, with a default for anyone missing. const [top = { name: 'nobody' }] = passed; console.log(`Top of the class: ${top.name}`); // Objects print expanded, so you can look inside them. console.log(top);
Output
Rendered by your browser