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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:41:02+00:00 2026-06-14T02:41:02+00:00

i have a few li’s: <ul> <li class=one> <input type=text class=form_input placeholder=Type something…> </li>

  • 0

i have a few li’s:

<ul>
    <li class="one">
        <input type="text" class="form_input" placeholder="Type something...">
    </li>
    <li class="two">
        <input type="text" class="form_input" placeholder="Type something else...">
    </li>
</ul>

i am trying to create a array similar to:

[
    0[
        'placeholder' : 'Type something...'
    ]
    1[
        'placeholder' : 'Type something else...'
    ]
]

i use a method like this

var lineText = function(elements) {
var myData = new Array();

elements.each(function(index, data) {
    var li = $(this);

    myData["placeholder"] = li.find('.form_input').attr("placeholder");

            console.log(data); returns the li objects
});

console.log(myData);
};

from this i get [placeholder: "Type something..."], basically one item in my array, instead of 2

i can’t use push like this:

myData["placeholder"].push(li.find('.form_input').attr("placeholder")); //Cannot call method 'push' of undefined 

or add another dimension to the array

myData[index]["placeholder"] = li.find('.form_input').attr("placeholder"); //Cannot set property 'placeholder' of undefined 

any ideas? thanks

  • 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-06-14T02:41:03+00:00Added an answer on June 14, 2026 at 2:41 am

    It sounds like you want an array of “associative arrays”. In JavaScript instead of associative arrays you can make objects can behave the same way. Meaning your above array would look like this in literal syntax.

    var a = [ { 'placeholder': 'Type something...' },
              { 'placeholder': 'Type something else...' } ];
    

    Where a[ 0 ][ 'placeholder' ] will return the string 'Type something...'. Since this uses objects, properties can’t be pushed because they require some key. Instead you would write something like a.push( { 'placeholder': 'Type more stuff...' } ).

    If you only plan to add placeholders to the array there’s no need in using objects, just make an array of strings like this.

    var placeholders = [ 'Type something...', 'Type something else...' ];
    

    But when using my first solution, your function would become

    var lineText = function(elements) {
        var myData = new Array();
    
        elements.each(function(index, data) {
            var li = $(this);
            var placeholderData = new Object();
    
            placeholderData["placeholder"] = li.find('.form_input').attr("placeholder");
            myData.push(placeholderData);
            console.log(data); returns the li objects
        });
    
        console.log(myData);
    };
    

    Live example here http://jsfiddle.net/vU36T/6/

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

Sidebar

Related Questions

I have few text fields like SSN , phone number and email id. I
I have few TabPages and each contains rich text box. How can I access
I have few question in xcode 4.2 developing.In that i create one application for
I have few tabs with input on each tab. I am using and I
i have few texboxt and dropdownlist, which their id would be something like txtName1,
I have few Vaadin tabs one of them is displaying an table and some
I have few text files that has some key words. I have to select
I have few form fields, each input and label is wrapped inside a div
I have few DB tables, witch are build using inheritance from one table witch
I have few concrete which uses the following type of interface interface IActivity<T> {

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.