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:

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