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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:46:55+00:00 2026-05-26T01:46:55+00:00

I have an array that is created dynamic from an xml document looking something

  • 0

I have an array that is created dynamic from an xml document looking something like this:

myArray[0] = [1,The Melting Pot,A]
myArray[1] = [5,Mama's MexicanKitchen,C]
myArray[2] = [6,Wingdome,D]
myArray[3] = [7,Piroshky Piroshky,D]
myArray[4] = [4,Crab Pot,F]
myArray[5] = [2,Ipanema Grill,G]
myArray[6] = [0,Pan Africa Market,Z]

This array is created within a for loop and could contain whatever based on the xml document

What I need to accomplish is grouping the items from this array based on the letters so that all array objects that have the letter A in them get stored in another array as this

other['A'] = ['item 1', 'item 2', 'item 3'];
other['B'] = ['item 4', 'item 5'];
other['C'] = ['item 6'];

To clarify I need to sort out items based on variables from within the array, in this case the letters so that all array objects containing the letter A goes under the new array by letter

Thanks for any help!

  • 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-26T01:46:55+00:00Added an answer on May 26, 2026 at 1:46 am

    You shouldn’t use arrays with non-integer indexes. Your other variable should be a plain object rather than an array. (It does work with arrays, but it’s not the best option.)

    // assume myArray is already declared and populated as per the question
    
    var other = {},
        letter,
        i;
    
    for (i=0; i < myArray.length; i++) {
       letter = myArray[i][2];
       // if other doesn't already have a property for the current letter
       // create it and assign it to a new empty array
       if (!(letter in other))
          other[letter] = [];
    
       other[letter].push(myArray[i]);
    }
    

    Given an item in myArray [1,”The Melting Pot”,”A”], your example doesn’t make it clear whether you want to store that whole thing in other or just the string field in the second array position – your example output only has strings but they don’t match your strings in myArray. My code originally stored just the string part by saying other[letter].push(myArray[i][1]);, but some anonymous person has edited my post to change it to other[letter].push(myArray[i]); which stores all of [1,”The Melting Pot”,”A”]. Up to you to figure out what you want to do there, I’ve given you the basic code you need.

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

Sidebar

Related Questions

I have byte array as input. I would like to convert that array to
I have some simple XML which I would like to parse into an array
I have created a dynamic list picker script using Jquery 1.3 and PHP that
I'm inserting some items into array with randomly created indexes, for example like this:
I have dynamic array in struct and a method that uses the dynamic array.
I have created a compound control that I am reusing in multiple activities. This
I have this iPhone app that has an array containing around 50 to 100
Say I have a dynamic array like: int* integers = new int[100]; Is there
I have an array that contains a list of vertices which I copy to
Say I have an array that represents a set of points: x = [2,

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.