Agyan
adda
Run
Reset
Copy
JavaScript Tutorial › JS Array Methods › map, filter and reduce
Back to tutorial
Code
Edit, then press Run or Ctrl+Enter
<pre id="out"></pre> <script> const students = [ { name: 'Asha', marks: 82 }, { name: 'Ravi', marks: 45 }, { name: 'Neha', marks: 91 }, { name: 'Aman', marks: 28 } ]; const names = students.map(s => s.name); const passed = students.filter(s => s.marks >= 33); const topper = students.find(s => s.marks > 90); const total = students.reduce((sum, s) => sum + s.marks, 0); const sorted = [...students].sort((a, b) => b.marks - a.marks); document.getElementById('out').textContent = [ 'Names: ' + names.join(', '), 'Passed: ' + passed.map(s => s.name).join(', '), 'Topper: ' + topper.name, 'Average: ' + (total / students.length).toFixed(1), 'Rank list: ' + sorted.map(s => s.name).join(' > ') ].join('\n'); </script>
Result