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

The Archive Base Latest Questions

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

var arr = $(.producttypeid); var premiumtypecodes = Array(arr.length); for (var i = 0; i

  • 0
var arr = $(".producttypeid");
var premiumtypecodes = Array(arr.length);
for (var i = 0; i < arr.length; i++)
    premiumtypecodes[i] = arr[i].value;

The above code does not seem to work. The intent is to assign the output to an array. Anything that I am missing.
Why this simple code does not work? Reasoning would be highly appreciated….

Based on the feedback I am adding sample markup and adding details to make my intent unambigous.

<input class="producttypeid" type="hidden" value="512">

I want to extract the value from all tags using style producttypeid and make an array

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

    Here’s how I’d do it:

    var arr = $(".producttypeid");
    var premiumtypecodes = [];
    arr.each(function(index) {
        premiumtypecodes[index] = this.value;
    });
    

    That assumes all of the matching elements are input elements (because of the use of value). If some of them may be textarea or select elements, then change the line inside the iterator function to:

        premiumtypecodes[index] = $(this).val();
    

    If they’re not form fields at all, you’ll have to define what you mean by their “value” (e.g., you might use $(this).text() to get their text content, or $(this).html() to get their markup, or something else entirely).

    I’m not immediately seeing any problem with your version other than that you’re missing an i after var:

    for (var = 0; i < arr.length; i++)
    //       ^--- here
    

    Other than that, it should have worked, but note that although Array(arr.length) works, the usual way to write it is new Array(arr.length) (and there’s no need to pre-set the length; JavaScript arrays aren’t really arrays so you don’t get the usual benefit of doing that).

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

Sidebar

Related Questions

I have a jQuery array: var arr = $('input[name$=recordset]'); I am getting the value
I have this array: var arr = []; arr.push({name:k1, value:abc}); arr.push({name:k2, value:hi}); arr.push({name:k3, value:oa});
Hi when I have an array in actionscript var arr : Array = new
I have an array of integers in string form: var arr = new string[]
var arr = new Array(); arr[0] = 'Departmental News' arr[1] = 'Departmental News' arr[2]
In Delphi, it is possible to create an array of the type var Arr:
Currently, I am creating a 3d array in js using the following: var arr
var arr = [[1,2,3],[4,5,6],[7,8,9]]; function out(ar){ var interval = setInterval(function(){ for (var i=0; i<ar.length;i++){
I have a jQuery post something like var arr = ['some', 'string', 'array']; jQuery.post('saveTheValues',
I have the following code in a test case on jsPerf: var arr =

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.