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:

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