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

  • Home
  • SEARCH
  • 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 8532561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:44:36+00:00 2026-06-11T09:44:36+00:00

How to write this script properly so I can match the value on the

  • 0

How to write this script properly so I can match the value on the object.

var objGroup = [
  { "color": "YELLOW", "number": "11,7,44,22" },
  { "color": "BLUE", "number": "8,20,9" },
  { "color": "GREEN", "number": "12,34,55" }
];
objGroup.map(function (groupNum) {
  if (groupNum.number== "11") {
    alert(groupNum.color);
  } else {
    return null
  }
});​
  • 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-11T09:44:38+00:00Added an answer on June 11, 2026 at 9:44 am

    This will return the object that has a number value that contains the supplied number.

    var objGroup = [
      { "color": "YELLOW", "number": "11,7,44,22" },
      { "color": "BLUE", "number": "8,20,9" },
      { "color": "GREEN", "number": "12,34,55" }
    ];
    
    var found = findItem(objGroup, '11');
    
    function findItem(array, value) {
        for (var i = 0; i < array.length; i++) {
            if (array[i].number.split(',').indexOf(value) >= 0) {
               return objGroup[i];
            }
        }
    }
    
    if (found) {
        alert(found.color);
    }
    

    http://jsfiddle.net/rVPu5/

    Alternative using newer .filter function which won’t be as widely supported:

    var found = objGroup.filter(function(item) {
        if (item.number.split(',').indexOf('11') >= 0) {
            return true;
        }
        return false;
    });
    
    if (found.length > 0) {
        alert(found[0].color);
    }
    

    http://jsfiddle.net/rVPu5/2/

    Finally – the jQuery version:

    var found = $.map(objGroup, function(item) {
        if (item.number.split(',').indexOf('11') >= 0) {
            return item;
        }
    });
    
    if (found.length > 0) {
        alert(found[0].color);
    }
    

    http://jsfiddle.net/rVPu5/3/

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

Sidebar

Related Questions

Can someone explain why this script throws an exception? $byteArray = @(1,2,3) write-Output (
Can someone write a PHP script that reproduces the functionality of this linux shell
This script cannot find bannersize unless I write <div id=bannersize></div> before the javascript. The
I'm trying to write a batch script, this script is responsible to launch a
i write a script to list my file from Update directory with this option:
I have to write a Matlab script that does this: The input is 2
I am trying to write a python script that takes record data like this
I have to write a script which will be hosted on differents domains. This
I am trying to write my very first python script. This was working but
Not sure this is possible, but looking to write a script that would return

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.