Search
Close this search box.
Search
Close this search box.
Search
Close this search box.

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