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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:07:28+00:00 2026-06-16T04:07:28+00:00

I have a string that I am splitting using string.split(‘ ‘); in order to

  • 0

I have a string that I am splitting using string.split(' '); in order to turn the string into an array.

suppose I have these two tables, table1 and table2.

<table border="1" id="table1">
    <tr>
        <th colspan="2">Image One</th>
    </tr>
    <tr>
        <td style="width:40%;"><img src="airplane.jpg" alt="Image 1"></td>
        <td>
            <dl>
              <dt>airplane</dt>
              <dt>flight</dt>
              <dt>travel</dt>
              <dt>military</dt>
              <dt>word war</dt>
              <dt>GI</dt>
            </dl>
        </td>
    </tr>
</table>

<table border="1" id="table2">
    <tr>
        <th colspan="2">Image Two</th>
    </tr>
    <tr>
        <td style="width:40%;"><img src="apple.jpg" alt="Image 1"></td>
        <td>
            <dl id="tags">
              <dt>red</dt>
              <dt>apple</dt>
              <dt>round</dt>
              <dt>fruit</dt>
              <dt>healthy</dt>
              <dt>doctor</dt>
            </dl>
        </td>
    </tr>
</table>

right now for testing purposes I have an id of tags on table2‘s dl.

I am using a function to turn that DL (#tags) into an array

function getArray(id) {
var node, list, arrValue;

    array = [];
    for (node = document.getElementById(id).firstChild;
        node;
        node = node.nextSibling) {
        if (node.nodeType == 1 && node.tagName == 'DT') {
            array.push(node.innerHTML);
        }
    }
    console.log(array)
}

in order to check it against my original string to see if any of the values match.
However, I am going to have multiple DT‘s that the string is going to be check against. Would it be correct to add all the tables into a 3d array and then check the values in the string against the 3d array? or is there a better approach?

UPDATE

The problem is:

I am eventually going to have tables filled with an image and tags. Essentially I want to be able to search those tags against my string (which will be separated into an array) then return the image with the most tags in the string. I am trying to figure out the best way to do that.
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-06-16T04:07:29+00:00Added an answer on June 16, 2026 at 4:07 am

    You wouldn’t use a three-dimensional array, but only a two-dimensional one with tables and their tags. Or, as Alnitak already mentioned, even better a lookup object:

    var map = {};
    var dls = document.getElementsByTagName('dl');
    for (var i = 0, i < dls.length; i++) {
        var tableid = dls[i].id; // identifier?
        var dts = dls[i].getElementsByTagName('dt'); // assuming you don't nest them
        for (var j = 0; j < dts.length; j++) {
            var text = dts[j].textContent || dts[i].innerText;
            var tags = text.split(/\s+/);
            for (var k=0; k<tags.length; k++)
                if (tags[k] in map)
                    map[tags[k]].push(tableid);
                else
                    map[tags[k]] = [tableid]; // an array
        }
    }
    /* now, map could look like this:
    {
        word: ["table1"],
        war: ["table1"],
        red: ["table2"],
        double: ["table1", "table2"], // tags in more than one table
        …
    }
    */
    

    To get the table with the most tags in the string you now can use a function like this, which returns the respective tableids sorted by tag occurence:

    function getHighestTables(string) {
        var tags = string.split(/\s+/);
        var tablecounts = {};
        for (var i=0; i<tags.length; i++) {
            var tables = map[tags[i]] || [];
            for (var j=0; j<tables.length; j++) {
                var tableid = tables[j];
                if (tableid in tablecounts)
                    tablecounts[tableid]++;
                else
                    tablecounts[tableid] = 1;
            }
        }
    /*  tablecounts might now look like this:
        {
            table1: 2
            table2: 5
        }
    */
        return Object.keys(tablecounts).sort(function (a, b) {
            return tablecounts[b] - tablecounts[a];
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Arduino that is processing a string by splitting it into an
Hi I have a string of numbers separated by commas, 100,200,300,400,500 that I'm splitting
I have the following function that does string splitting: on splitText(aString, delimiter) set retVal
I have string that look like Array that fetched from other webservice like this
I have a string like: {A}{B}={C}{D}<{E}{F}<= What I want to do is split that
I have an 6digit integer, let's say 153060 that I'll like to split into
I have an Array of Strings that are in order A-Z. I was wondering
Is there a nice linqy way of splitting a FormCollection into a Dictionary<string,string> that
I have a seemingly simple problem of splitting a comma separated String into tokens,
I have the following String: (X,Y,Z),(A,B,C),(R,S,T) I want to split this into a multi-dimensional

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.