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:

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