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:

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