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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:15:12+00:00 2026-05-25T11:15:12+00:00

I have an array where there are repeated values. I need to group like

  • 0

I have an array where there are repeated values. I need to group like elements, and when the value changes create a new “section”.

My array is something like

{section: "An Hour before Dinner", title: "Cook peas"},
{section: "An Hour before Dinner", title: "Take pie out"},
{section: "As guests arrive", title: "Mix drinks"},
{section: "Just Before Dessert", title: "Reheat at 325 about 20 minutes."},
{section: "Just Before Dessert", title: "Cut and serve."},

I will need to do something like

An Hour Before Dinner
  Cook peas
  Take pie out
As guests arrive
  Mix Drinks
Just before dessert
  Reheat at 325 about 20 minutes.
  Cut and serve.

Due to the fact that sometimes my array might have fewer or more elements, I need to loop it, and when the value changes create a new heading with the new value and then loop through the elements until the next different item comes up and create the next heading etc.

  • 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-25T11:15:12+00:00Added an answer on May 25, 2026 at 11:15 am

    This should do the trick:

    var arr = [
        {section:"An Hour before Dinner", title:"Cook peas"},
        {section:"An Hour before Dinner", title:"Take pie out"},
        {section:"As guests arrive", title:"Mix drinks"},
        {section:"Just Before Dessert", title:"Reheat at 325 about 20 minutes."},
        {section:"Just Before Dessert", title:"Cut and serve."}
    ];
    var s = null;
    
    var html = "";
    for (var i = 0, l = arr.length; i<l; i++) {
        var r = arr[i];
        if (r.section != s) {
            // New section
            s = r.section;
            html += "<h1>"+s+"</h1>"
        } else {
            // Continue old section
        }
        html += "<p>"+r.title+"</p>";
    }
    
    var div = document.createElement('div');
    div.innerHTML = html;
    document.body.appendChild(div);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a array with a variable amount of values. Is there a more
I have two arrays of values like X,Y,Z and 1,2 There is a table
I have an array with 16 elements. I would like to evaluate these to
I have an array with values $somearray = array('car','bike','legs,'car'). I'd like to find out
I have an array of users who are managers. However there are repeated Users.
Say I have an array of number a <- c(1,2,3,6,7,8,9,10,20) if there a way
Say you have an array, data, of unknown length. Is there a shorter method
Is there any method like the array_unique for objects? I have a bunch of
Does anyone know do there have any way that I can encrypt the array
I have an array of integers like these; dim x as integer()={10,9,4,7,6,8,3}. Now I

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.