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:

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