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:

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