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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:15:52+00:00 2026-05-26T02:15:52+00:00

my script is getting some array from php server side script. result = jQuery.parseJSON(result);

  • 0

my script is getting some array from php server side script.

result = jQuery.parseJSON(result);

now I want to check each variable of the array.

if (result.a!='') { something.... }
if (result.b!='') { something.... }
....

Is there any better way to make it quick like in php ‘foreach’ , ‘while’ or smth ?

UPDATE

This code ( thanks to hvgotcodes ) gives me values of variables inside the array but how can I get the names of variables also ?

for(var k in result) {
   alert(result[k]);
}

UPDATE 2

This is how php side works

$json = json_encode(array("a" => "test", "b" => "test",  "c" => "test", "d" => "test"));
  • 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-26T02:15:53+00:00Added an answer on May 26, 2026 at 2:15 am

    You can do something like

    for(var k in result) {
       console.log(k, result[k]);
    }
    

    which loops over all the keys in the returned json and prints the values. However, if you have a nested structure, you will need to use

    typeof result[k] === "object"
    

    to determine if you have to loop over the nested objects. Most APIs I have used, the developers know the structure of what is being returned, so this is unnecessary. However, I suppose it’s possible that this expectation is not good for all cases.

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

Sidebar

Related Questions

I'm getting about 500 rows back from a DB that my PHP script connects
I'm trying to POSTing some data (a JSON string) from a php script to
We were running Tarantino in a Nant build script but we're getting some new
I'm getting an error message from a python script at position 21490 . How
Aside from writing an alias or script, is there a shorter command for getting
I'm having some difficulty getting this script to execute properly. The create_rss function does
I need some help in converting my script from using mysql to mysqli I
I am writing a PHP script where the inputs are: From date To date
I am having difficulty getting started with interfacing my PHP script to Moodle 2.0
I am making a PHP script that does some stuff for me, so 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.