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:

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