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:

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