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:

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