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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:06:40+00:00 2026-06-02T22:06:40+00:00

I am currently using .append to join two or more arrays together to form

  • 0

I am currently using .append to join two or more arrays together to form a phrase as you can see in this jsfiddle: jsfiddle append array.

function P1(phrase) {
    var sen = ('<a class="senword">' + phrase[0] + '<br/>' + phrase[1] + ' </a>');
       return sen;
}

var words = [
['one', '一'],    
['eight','八'],
['hundred','百'],
];

$("#onehundred").append(P1(words[0])).append(P1(words[2]));
$("#eighthundred").append(P1(words[1])).append(P1(words[2]));

However I need a way to append arrays by using an array value, e.g. ‘hundred’ instead of the index number e.g. [2]. This is because each time I add new vocabulary to the ‘words’ array, the index number is obviously changing, which means I would need to manually change all the index numbers for the phrases.

So is there a way to join arrays by using a value instead of an index number, as this value wouldn’t change no matter how many new words I added?

For example instead of:

$("#onehundred").append(P1(words[0])).append(P1(words[2]));

Have something like this (but obviously this is not correct):

$("#onehundred").append(P1(words['one'])).append(P1(words['hundred']));

PS
I don’t mind changing to a literal array if it helps, e.g.:

var words = [
{'english':'hundred', 'chinese':'百'},
];

Thanks for any suggestions!

  • 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-02T22:06:42+00:00Added an answer on June 2, 2026 at 10:06 pm

    Change your data structure to an object:

    var words = {
        'one': '一',    
        'eight': '八',
        'hundred': '百'
    };
    

    Then change your P1 function to accept the property name, and have it do the look-up…

    function P1(key) {
        var sen = ('<a class="senword">' + words[key] + '<br/>' + key + ' </a>');
           return sen;
    }
    

    And then just pass the property name…

    $("#onehundred").append(P1('one')).append(P1('hundred'));
    $("#eighthundred").append(P1('eight')).append(P1('hundred'));
    

    DEMO: http://jsfiddle.net/DgAzz/


    If you can’t change the initial structure, then create the object from it…

    var words_map = {};
    
    $.each(words, function(i, val) {
        words_map[val[0]] = val[1];
    });
    

    DEMO: http://jsfiddle.net/DgAzz/1/

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

Sidebar

Related Questions

I'm currently using the following code to append a X link to each element
Here is the code I'm currently using: $.ajax({ success: function(){ $('.post_container').append('test <br />'); }
Currently using MySQL version 5.1.6 This is my first real world build and so
Currently using Xcode 4.2 and I have two view controllers (1 and 2). I
I'm currently using this for turning an enum into a radio control, public static
Hey all i am currently using this code below to gather my returned XML
I have a ClickOnce-deployed application and I'm currently using this to detect the first
So I am currently using this solution to scroll a div to the bottom
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
Currently using Google Analytics as a supplement to our paid tracking software, but neither

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.