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:

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