Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 666079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:46:45+00:00 2026-05-13T23:46:45+00:00

It has been done to death pretty much, here on SO and around the

  • 0

It has been done to death pretty much, here on SO and around the ‘Net. However I was wondering if there was a way to leverage the standard min/max functions of:

Array.max = function(array) {
    return Math.max.apply(Math, array);
};

Array.min = function(array) {
    return Math.min.apply(Math, array);
};

So I can search across an array of objects of say:

function Vector(x, y, z) { this.x = x; this.y = y; this.z = z; }
var ArrayVector = [ /* lots of data */ ];
var min_x = ArrayVector.x.min(); // or
var max_y = ArrayVector["y"].max();

Currently I have to loop through the array and compare the object values manually and craft each one to the particular need of the loop. A more general purpose way would be nice (if slightly slower).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:46:45+00:00Added an answer on May 13, 2026 at 11:46 pm

    You could make some changes to your Array.minand max methods to accept a property name, extract that property of each object in the array, with the help of Array.prototype.map, and the max or min value of those extracted values:

    Array.maxProp = function (array, prop) {
      var values = array.map(function (el) {
        return el[prop];
      });
      return Math.max.apply(Math, values);
    };
    
    var max_x = Array.maxProp(ArrayVector, 'x');
    

    I just want to mention that the Array.prototype.map method will be available on almost all modern browsers, and it is part of the ECMAScript 5th Edition Specification, but Internet Explorer doesn’t have it, however you can easily include an implementation like the found on the Mozilla Developer Center.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this has been done a hundred times, but i'm hoping there is
Has there been any work done on any hypothetical hardware + OS architecture or
First of all, sorry if this has been asked before. I've done a pretty
I understand that this question has been done to death so I'll apologise in
I know that this question has been done to death at StackOverflow and that
This question has been done to death, and I would agree that enums are
I know that the topic of C++ delegates has been done to death, and
So, I know this has been done to death but all the answers I've
I realise that padding in Twitter Bootstrap has been done somewhat to death and
Is there anything that has been done by somebody to make it a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.