StepsEasy
JS Array Methods - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
javascript
const fruits = ['apple', 'banana', 'cherry', 'date']; // map - transform each element const upper = fruits.map(f => f.toUpperCase()); // filter - keep matching elements const long = fruits.filter(f => f.length > 5); // find - first match const found = fruits.find(f => f.startsWith('c')); // reduce - accumulate const lengths = fruits.reduce((sum, f) => sum + f.length, 0); console.log(upper); // ['APPLE', 'BANANA', 'CHERRY', 'DATE'] console.log(long); // ['banana', 'cherry'] console.log(found); // 'cherry' console.log(lengths); // 21
Result
Click "Run" to execute the code...
Loading runtime...
Ready
JAVASCRIPT | In-Browser Execution