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:

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