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 8661447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:30:00+00:00 2026-06-12T16:30:00+00:00

Possible Duplicate: Find object by id in array of javascript objects So I have

  • 0

Possible Duplicate:
Find object by id in array of javascript objects

So I have this:

mapArray=
[{"Title":"crop_rotation","subs":"5,6,7,10"},
{"Title":"cover_crops","subs":"2,5,7,8,9,13,14"},
{"Title":"binary_wetlands","subs":"1,2,3,4,5,6,7,8,9,10,11"}]

I am trying to access the subs value based on the Title. I am trying

listofSubs=mapArray["crop_rotation"]("subs");

I don’t get anything returned. What am I missing here? I need to take that list and convert to a string but I assume it will come out as a string since I have the object already parsed? Thanks in advance

  • 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-06-12T16:30:02+00:00Added an answer on June 12, 2026 at 4:30 pm

    First you have to find the object with the specific title. You have to do this by iterating over the array and comparing each object’s Title against your value:

    function find(arr, key, value) {
        for(var i = 0, l = arr.length; i < l; i++) {
            if(arr[i][key] === value)) {
                return arr[i];
            }
        }
        // return {}; // if you would want it null-safe
    }
    

    Then you can access the corresponding subs property:

    var obj = find(mapArray, 'Title', 'crop_rotation');
    if(obj) {
        var listofSubs = obj.subs;
    }
    

    An explanation for why your code does not work:

    mapArray["crop_rotation"]("subs");
    //      |-      1      -|-   2  -|
    
    • |1| tries to access the property crop_rotation of the object in mapArray. Arrays don’t have such properties and in your case no object does. crop_rotation is the value of one of the properties.
    • |2| is a function call. It tries to call the function referenced by mapArray["crop_rotation"] and passes "subs" as first argument. It throws an error if mapArray["crop_rotation"] is not a function (like in your case).

    Further information:

    • MDN JavaScript Guide # Arrays
    • MDN JavaScript Guide # Working with Object
    • Access / process (nested) objects, arrays or JSON
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Find object by id in an array of JavaScript objects How to
Possible Duplicate: indexOf method in an object array? I have a javascript array which
Possible Duplicate: CakePHP: Call to a member function find() on a non-object I have
Possible Duplicate: Easiest way to find duplicate values in a JavaScript array Javascript array
Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like
Possible Duplicate: Easiest way to find duplicate values in a JavaScript array I am
Possible Duplicate: Debug Javascript Every now and then i have one jquery object and
Possible Duplicate: What does var that = this; mean in javascript? I often find
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) Sizeof array
Possible Duplicate: How to find a duplicate of length 5 in a single array.

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.