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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:15:56+00:00 2026-05-30T04:15:56+00:00

I am writing one function on Javascript which needs to address all the anynymous

  • 0

I am writing one function on Javascript which needs to address all the anynymous types in a JSON object.

For example,

Typed=  {
 emails: [{email:'a@a.com'}, {email:'b@a.com'}, {email:'c@a.com'}, {email:'d@a.com'}]
};

is an example of typed array in a JSON because each element inside the array is typed email

while,

Anon=  {
 emails: ['a@a.com', 'b@a.com', 'c@a.com', 'd@a.com']
};

is a JSON object where emails is collection of some anonymous objects.

Is there any ways that I can differentiate between both in JQuery or Javascript?

  • 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-30T04:15:57+00:00Added an answer on May 30, 2026 at 4:15 am

    The simplest solution is to have the JSON source only return one of the two forms. Then you don’t have to branch in your client.

    If that’s not an option, you could get the values out with JavaScript’s handy lazy-evaluation of boolean expressions:

    var em = json.emails[0].email || json.emails[0];
    

    That statement will prefer the array-of-objects version, but use the array-of-strings version as a fallback.

    (edited in response to clarifying comment below)

    You can determine what properties a JS object has at runtime like this:

    function enumerate(targetObject){
        var props = [];
        for (var propName in targetObject ){
            props.push(propName);
        }
        return props;
    }
    
    console.log(enumerate({foo:1, bar:'baz'}),join(',')); //"foo, bar"
    

    you could then modulate your logic on the basis of the properties you get back. You’ll want to make sure you understand prototypes (specifically what Object.hasOwnProperty does and means), too.

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

Sidebar

Related Questions

I'm writing a JavaScript function that needs to uphold three properties: be very small
While writing javascript, one can define a method in 3 different ways. 1] A
I’ve two individual pages which actual needs the same kind of function so I’ll
I'm writing an application which uses ASP.NET MVC with JSON.NET as the server, sending
I'm writing some JavaScript with three classes, one for Roofs, one for Garages, and
I'm writing a javascript function and in compact javascript design fashion, the type/length of
Basically what I'm after is, following squashing all my JavaScript into one file (or
One of the reasons that I tend to dread writing Javascript for anything other
I'm writing on a MSN Plus script, which is in fact javascript. For interop
I often find myself writing one off queries to either answer someone's question or

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.