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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:14:11+00:00 2026-06-05T09:14:11+00:00

I have a JSON response like this: var errorLog = [[\comp\,\Please add company name!\],

  • 0

I have a JSON response like this:

 var errorLog = "[[\"comp\",\"Please add company name!\"],
                 [\"zip\",\"Please add zip code!\"],
                  ...

Which I’m deserializing like this:

 var log = jQuery.parseJSON(errorLog);

Now I can access elements like this:

 log[1][1] > "Please add company name"

Question:
If I have the first value comp, is there a way to directly get the 2nd value by doing:

 log[comp][1]

without looping through the whole array.

Thanks for help!

  • 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-05T09:14:12+00:00Added an answer on June 5, 2026 at 9:14 am

    There are two was to do this, but neither avoids a loop. The first is to loop through the array each time you access the items:

    var val = '';
    for (var i = 0; i < errorLog.length; i++) {
        if (errorLog[i][0] === "comp") {
            val = errorLog[i][1];
            break;
        }
    }
    

    The other would be to work your array into an object and access it with object notation.

    var errors = {};
    for (var i = 0; i < errorLog.length; i++) {
        errors[errorLog[i][0]] = errorLog[i][1];
    }
    

    You could then access the relevant value with errors.comp.

    If you’re only looking once, the first option is probably better. If you may look more than once, it’s probably best to use the second system since (a) you only need to do the loop once, which is more efficient, (b) you don’t repeat yourself with the looping code, (c) it’s immediately obvious what you’re trying to do.

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

Sidebar

Related Questions

I have a JSON response (which I have no control over) similar to this:
I have this JSON response string: {d:{\ID_usuario\:\000130\,\Nombre\:null,\Vipxlo\:0,\Provmun\:null,\Descuentos\:null,\Listaviplocal\:null}}` With this code: - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
I have a json output array like this { data: [ { name: Ben
My JSON response looks like this : {sample:[{id:2,name:branch name},{id:3,name:branch name 2}]} My function looks
My JSON response looks like this : {sample:[{id:2,name:branch name},{id:3,name:branch name 2}]} My function looks
I have something like this coming as a JSON reponse: <span id=\my-id-527114\>Some data here</span>\n
We have a JSON response which can contain null values (e.g. { myValue: null
If i have this json response {error:repeated} Why the alert is not showed? It
i have this code for sending data var test={imagename:apple.jpg,x:13,y:33}; $.ajax({ type: POST, url: some.php,
I'm generating JSON response from PHP witch looks like this: { done:'1', options: [{

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.