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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:52:46+00:00 2026-05-28T04:52:46+00:00

I used to create an array in js var data = new Array(); data[‘id’]

  • 0

I used to create an array in js

var data = new Array();  
data['id'] = self.iframeFields.id.val();  
data['name'] = self.iframeFields.name.val();  
data['location'] = self.iframeFields.location.val();  
data['about'] = self.iframeFields.about.val();  
data['company'] = self.iframeFields.company.val();  
data['website'] = self.iframeFields.website.val();

but passing var data returns null value

but data['id'] return value.

What did I do wrong?

EDIT:
After nrabinowitz‘s answer, i was using

if ($.isArray( data )){
ajax({

        url: myurl,
        data: {
            method: "updateProfile",
            data: data
        },
        normalizeJSON: true,
        success: function( response ){
            // Check to see if the request was successful.
            if (response.success){
                alert(response);
            } else if (onError){
                // The call was not successful - call the error function.
                alert(response);
            }
        }
    });
       }

as it is an object not an array,

it was not returning nothing,

Removing

  if ($.isArray( data )){
        }

solves the issue.

  • 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-28T04:52:47+00:00Added an answer on May 28, 2026 at 4:52 am

    In Javascript, you want an object, not an array:

    var data = {};
    data['id'] = self.iframeFields.id.val();
    // etc...
    

    You’re expecting the array to work like an associative array in PHP, but Javascript arrays don’t work that way. I’m assuming you’re setting these values by key, and then trying to iterate through the array with something like a for loop – but while you can set values by key, because in Javascript an array is just another object, these values won’t be available in standard array iteration, and the length of the array will still be 0.

    EDIT: You note that you’re using jQuery’s .ajax() function to post the data to the server. The .ajax() method expects an object containing key/value pairs, and sends them to the server as a GET or POST parameters. So in your case, if you’re using an object as I describe above, your server will receive the parameters "id", "name", etc in the $_POST array – not a "data" parameter.

    I suspect, though I haven’t tested this, that using var data = new Array(); wouldn’t work at all, because of the way jQuery serializes the data passed to .ajax() – even though an array is also an object, jQuery checks if it’s an array and treats it differently:

    If the object passed is in an Array, it must be an array of objects in the format returned by .serializeArray()

    [{name:”first”,value:”Rick”},
    {name:”last”,value:”Astley”},
    {name:”job”,value:”Rock Star”}]

    So it wouldn’t use the key/value pairs you set at all – you would be passing an empty array and no parameters would be passed to the server.

    So the right approach here:

    1. Use var data = {};
    2. On the server, look for $_POST['id'], $_POST['name'], etc.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i used to create an instance of a singleton class like this: $Singleton =
I am used to create some crawlers to compile information and as I come
When programming C++ we used to create copy constructors when needed (or so we
in Web Forms i used to create WeebServices and PageMethods to be able to
What is the function used to create taxonomy terms in Drupal from the code?
What graphics library is used to create the graphics in the Solitaire and Freecell
Notification and NotificationManager are used to create icons to be placed on the top-left
The Win32 API call RegisterTypeLib() is used to create the registry keys necessary to
What libraries and/or packages have you used to create blog posts with code blocks?
I have an XML file that I used to create an XSD File and

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.