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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:44:10+00:00 2026-06-09T11:44:10+00:00

If the id:236 exists in spConfig[‘attributs’][125][‘options’] get the array that is contained in. How

  • 0

If the "id":"236" exists in spConfig['attributs'][125]['options'] get the array that is contained in.

How would you do this in jQuery ?

var spConfig = {
    "attributes": {
        "125": {
            "id": "125",
            "code": "pos_colours",
            "label": "Colour",
            "options": [{
                "id": "236",
                "label": "Dazzling Blue",
                "price": "0",
                "oldPrice": "0",
                "products": ["11148"]
            }, {
                "id": "305",
                "label": "Vintage Brown",
                "price": "0",
                "oldPrice": "0",
                "products": ["11786", "11787", "11788", "11789", "11790", "11791", "11792", "11793"]
            }]
        }

    }
  • 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-09T11:44:11+00:00Added an answer on June 9, 2026 at 11:44 am

    Your data structure is slightly complicated, but assuming options.ids are unique, you can use

    function foo(arg) {
        var filtered;
        $.each(spConfig.attributes, function() {
            filtered = $(this.options).filter(function() {
                return this.id == arg;
            });
        });
        return (filtered.length) ? filtered[0].products : [];
    }
    

    Fiddle

    The function to return an empty array when a nonexistent key is passed.

    Also, if you have more than one attribute property (other than 125) and want to iterate over them:

    function foo(arg) {
        var filtered=[];
        $.each(spConfig.attributes, function() {
            filtered.push($(this.options).filter(function() {
                return this.id == arg;
            }));
        });
        filtered = $(filtered).filter(function() {
            return this.length;
        });
        return (filtered.length) ? filtered[0][0].products : [];
    }
    

    Fiddle

    Or, if you’ll always access the property attribute[125], you may as well leave it hard-coded for simplicity:

    function foo(arg) {
        var filtered = $(spConfig.attributes[125].options).filter(function() {
            return this.id == arg;
        });
        return (filtered.length) ? filtered[0].products : [];
    }
    

    Fiddle

    Or passing the attribute property name if you need more customization.

    function foo(arg, attr) {
        var filtered = $(spConfig.attributes[attr].options).filter(function() {
            return this.id == arg;
        });
        return (filtered.length) ? filtered[0].products : [];
    }
    

    Fiddle

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

Sidebar

Related Questions

Say I have an array like this arr = [24, 21, 25, 40, 236,
I'm trying to open an URI with Swing that I get above error. What
I need to get the x/y positions of an element that is written like
This is my table CREATE TABLE IF NOT EXISTS `results_stock_all` ( `Result_Id` varchar(50) NOT
Why my localhosted files appear like this? http://109.236.82.36/upload/ Everything is undefined, the defined variables
I have an array like this: $tmb = Array( [xThis] => 12400 [fThat] =>
Suppose a query select streetAdr from Address returns 236 a1 road 333 a2 road
I am trying to list a directory on remote machine 10.31.236.56 I am using
Having this text file : Breathing 1:-29.9396 9:-32.0895 13:-35.6787 2:-36.8527 17:-37.3622 8:-38.0584 14:-38.5265 18:-38.7567
i have a table name preferences under this there are multiple columns but i

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.