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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:24:59+00:00 2026-05-26T09:24:59+00:00

Using this syntax: var position = array($(‘#ipadmenu > section’).attr(‘data-order’)); I cannot get my code

  • 0

Using this syntax:

var position = array($('#ipadmenu > section').attr('data-order'));

I cannot get my code to work. I have never used arrays before so im kind of lost on how to use them. (especially in jquery).

How would I make an array of all section elements and associate the value of data-order to that list. Example:

first section - data-order:1
second section - data-order:2

etc and then use that info afterwards.

Thank you!

  • 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-26T09:24:59+00:00Added an answer on May 26, 2026 at 9:24 am

    Since .attr just gets one attribute — the first one found by the jQuery selector — you need to build your array element by element. One way to do that is .each (you can also use .data to extract data attributes):

    var position = new Array;
    $('#ipadmenu > section').each(function() {
        position.push($(this).data('order'));
    });
    
    alert(position[0]);  // alerts "1"
    

    This will be an indexed array, not an associative array. To build one of those (which in JavaScript is technically an object, not any kind of array) just change the inner part of your .each loop:

    var position = {};
    $('#ipadmenu > section').each(function(i) {
        position["section"+i] = $(this).data('order');
    });
    

    The resulting object position can now be accessed like:

    alert(position['section1']); // alerts "1"
    

    A different approach involves using jQuery.map, but since that only works on arrays, not jQuery objects, you need to use jQuery.makeArray to convert your selection into a true array first:

    var position = $.map($.makeArray($('#ipadmenu > section')), function() {
        return $(this).data('order');
    } );  // position is now an indexed array
    

    This approach is technically shorter than using .each, but I find it less clear.

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

Sidebar

Related Questions

i am using this code <a onclick=javascript:var t=setInterval(GetUpdates(5,ajaxResult),300);>GetUpdates</a> but getting the syntax error
I am trying to create a multi dimensional array using this syntax: $x[1] =
Using this `$(function(){$(.signaler).click(function(){var element=$(this);var I = element.attr(id);var page = $('#page').attr('value');var info = id=+I+& page=+
What's the point using this syntax div.card > div.name What's the difference between this
What's the difference between reading a value from an SqlDataReader using this syntax: Dim
I've embedded a SWF into a class using this syntax above my class definition:
Using the C# object initializer syntax I can instantiate an anonymous object like this:
I want to achieve a syntax similar to this one using JS setters and
<script type=text/javascript> var $j = jQuery.noConflict(); $j(document).ready( function(){ //is this right syntax for jquery
To use initialization syntax like this: var contacts = new ContactList { { Dan,

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.