How to dump the for loop and stay alive

Facebook
Twitter
LinkedIn
Pinterest
WhatsApp
var arr  ['a', 'b', 'c', 'd', 'e'];
for (var i  0; i < arr.length; i++) {
  console.log(arr[i]);
}

The example array

var people  [{
  id: 1,  
  name: 'Alice',
  age: 16
},
{
  id: 2,
  name: 'Bob',
  age: 19
},
{
  id: 3,
  name: 'Carol',
  age: 15
},
{
  id: 4,
  name: 'David',
  age: 21
}];

Sum an array

var sum  0;for (var i  0; i < people.length; i++) {
  sum += people[i].age;
}
const sum  people.reduce(function(acc, person){
  return acc + person.age;
}, 0)
const sum  people.reduce((acc, person) > (acc + person.age), 0);

Interlude: a note about arrow functions

Filter an array

var adults  [];for (var i  0; i < people.length; i++) {
  if (people[i].age > 16) {
    adults.push(people[i]);
  }
}
const adults  people.filter(person > person.age > 16);

Find the element with max property

var oldest  {age: 0};for (var i  0; i < people.length; i++) {
  if (people[i].age > oldest.age) {
    oldest  people[i];
  }
}
const oldest  people.reduce((acc, person) > 
  person.age > acc.age ? person : acc
);

Extract a property from an array of objects

var names  [];for (var i  0; i < people.length; i++) {
  names.push(people[i].name);
}
const names  people.map(val > val.name);

Index an array of objects

var iPeople  {};for (var i  0; i < people.length; i++) {
  iPeople[people[i].id]  people[i];
}
const iPeople  people.reduce((acc, person) > {
  acc[person.id]  person;
  return acc;
}, {});

Find an element in array

var details  null;for (var i  0; i < people.length; i++) {
  if (people[i].name == 'Bob'){
    details  people[i];
    break;
  }
}
const details  people.find(val > val.name == 'Bob');

Summary

Subscribe for Email Updates:

Categories:

Tags:

Principles of Lean-Agile Leadership
RTE Role
Frameworks
Systems Thinking
System Archetypes
Portfolio for Jira
Jira Cloud
The Agile Coach
Kaizen
Agile Assembly Architecture
Agile Mindset
Presentation
Product Ownership
LeSS
speed at scale
LPM
Legacy Enterprise
Sprint Iteration
Software Development Estimation
Reading List
GanttBan
Lean Software Development
AI Artificial Intelligence
Risk Management in Kanban
Scrum Primer
Lean Agile
TDD
POPM
Atlaassian
BDD
Perfection Game
Agile Games
Lean Budgeting
LAB
Coaching Agile Teams
Agile Outsourcing
Program Increment
Scrum.org
ATDD vs. BDD
Professional Scrum with Kanban
Agile Basics
Lean Risk Management
Lean-Agile Budgeting
Large Scale Scrum
Agile Techniques
Rapid RTC
Lean and Agile Techniques
agileisrael
Release Train Engineer
Risk-aware Product Development
Hybrid Work
Agile Delivery
Manage Budget Creation
Elastic Leadership
Tips
A Kanban System for Software Engineering
Achieve Business Agility
Nexus and SAFe
Lean Agile Leadership
Daily Scrum
Scrum Guide
Planning
Implementing SAFe
Certified SAFe
Legacy Code
Effective Agile Retrospectives
Applying Agile Methodology
Agile Games and Exercises
Kanban 101
Agile Project Management
Agile and DevOps Journey
Agile for Embedded Systems
Built-In Quality
Software Development
System Integration Environments
Lean and Agile Principles and Practices
Change Management
Product Management
Covid19
Agile Program
Nexus
Agility
Video
Quality Assurance
Advanced Roadmaps
AgileSparks
Artificial Intelligence
Agile Israel
RTE
Agile Release Planning
Pomodoro Technique
Kanban Game
Value Streams
Test Driven Development
Iterative Incremental Development
Lean Agile Management
Agile Israel Events
Agile Risk Management
Sprint Planning
Risk Management on Agile Projects
Limiting Work in Progress
ROI
IT Operations
ScrumMaster Tales
Self-organization
Accelerate Value Delivery At Scale
Lean Startup
SPC
Agile Project
Agile Contracts Best Practices
Agile Testing Practices
Continuous Deployment
speed @ scale
Kanban
Spotify
Story Slicing
EOS®
Kanban Kickstart Example
Operational Value Stream
ART Success
Professional Scrum Product Owner
ATDD
Code
Managing Risk on Agile Projects
SAFe
Slides
ARTs
Implementation of Lean and Agile
Agile Community
PI Objectives
Nexus Integration Team
An Appreciative Retrospective
Scrum Values
RSA
Continuous Delivery
Amdocs
Agile Product Development
Scaled Agile Framework
Agile Exercises
Scrum Master Role
Releases Using Lean
Agile in the Enterprise
Scrum
WIP
Agile Product Ownership
Scrum Master
SAFe DevOps
QA
Nexus vs SAFe
Agile India
Agile
SA
Introduction to Test Driven Development
DevOps
Agile Release Management
What Is Kanban
Continuous Planning
The Kanban Method
Scrum and XP
Sprint Retrospectives
System Team
Engineering Practices
Entrepreneurial Operating System®
NIT
Lean Agile Basics
Introduction to ATDD
Jira Plans
Acceptance Test-Driven Development
lean agile change management
Lean Agile Organization
Continuous Improvement
Agile Development
Lean-Agile Software Development
Kaizen Workshop
SAFe Release Planning
ALM Tools
Scrum With Kanban
Managing Projects
Agile Marketing
Kanban Basics
Development Value Streams
Professional Scrum Master
Webinar
Business Agility
Games and Exercises
PI Planning
Enterprise DevOps
Continuous Integration
Nexus and Kanban
Process Improvement
AgileSparks
Logo
Enable registration in settings - general

Contact Us

Request for additional information and prices

AgileSparks Newsletter

Subscribe to our newsletter, and stay updated on the latest Agile news and events

This website uses Cookies to provide a better experience
Shopping cart