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:

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