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:

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