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:

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