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:

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