Answers for "how to Rearrange an array of objects based on a common key/value pair in php"

PHP
0

how to Rearrange an array of objects based on a common key/value pair in php

// Person array with name and Age
const person = [
  {
    name: 'Jim',
    color: 'blue',
    age: 22,
  },
  {
    name: 'Sam',
    color: 'blue',
    age: 33,
  },
  {
    name: 'Eddie',
    color: 'green',
    age: 77,
  },
];

// Add their sum of ages
const sumOfAges = person.reduce((sum, currentValue) => {
  return sum + currentValue.age;
}, 0);

console.log(sumOfAges); // 132
Posted by: Guest on July-30-2021
0

how to Rearrange an array of objects based on a common key/value pair in php

// Person array with name and Age
const person = [
  {
    name: 'Jim',
    color: 'blue',
    age: 22,
  },
  {
    name: 'Sam',
    color: 'blue',
    age: 33,
  },
  {
    name: 'Eddie',
    color: 'green',
    age: 77,
  },
];

// Add their sum of ages
const sumOfAges = person.reduce((sum, currentValue) => {
  return sum + currentValue.age;
}, 0);

alert(sumOfAges); // 132
Posted by: Guest on July-30-2021

Code answers related to "how to Rearrange an array of objects based on a common key/value pair in php"

Browse Popular Code Answers by Language