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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:45:38+00:00 2026-05-26T15:45:38+00:00

How do you count patterns in record fields and create an array of it?

  • 0

How do you count patterns in record fields and create an array of it?

For example:

Searching in (using my example below) currently gives me multiple outputs of

0 0 (**in** seen at index 0 of book 0 title record)

0 13 (**in** seen at index 13 of book 0 title record)

1 19 (**in** seen at index 0 of book 1 title record)

2 -1 (**in** not seen at any index of title record)

Ideally I would like the code to return:

2,1,0 (**in** seen 2 times in book 0 title record, **in** seen 1 time in 
book 1 title record and **in** not seen in book 2 title record

Thanks in advance!

books = [
    {
    title: "Inheritance: Inheritance Cycle, Book 4",
    author: "Christopher Paolini",
    },
{
    title: "The Sense of an Ending",
    author: "Julian Barnes"},
{
    title: "Snuff Discworld Novel 39",
    author: "Sir Terry Pratchett",
    }
]
search = prompt("Title?");

function count(books, pattern) {
    if (pattern) {
        var num = 0;
        var result = [];
        for (i = 0; i < books.length; i++) {
            var index = books[i].title.toLowerCase().indexOf(pattern.toLowerCase());
            do {
                alert(i + " " + index);
                index = books[i].title.toLowerCase().indexOf(pattern.toLowerCase(), index + 1);
            }
            while (index >= 0)
            num = 0;
        }
        return result;
    }
    else {
        return ("Nothing entered!");
    }
}
alert(count(books, search));
  • 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-26T15:45:38+00:00Added an answer on May 26, 2026 at 3:45 pm

    Use String.prototype.match, it returns an array of the matches (or null if there were none), the length of the array tells you how many matches there were. e.g.

    var books = [
        {
        title: "Inheritance: Inheritance Cycle, Book 4",
        author: "Christopher Paolini",
        },
    {
        title: "The Sense of an Ending",
        author: "Julian Barnes"},
    {
        title: "Snuff Discworld Novel 39",
        author: "Sir Terry Pratchett",
        }
    ];
    var result = [];
    var re = /in/ig; 
    var matches;
    for (var i=0, iLen=books.length; i<iLen; i++) {
      matches = books[i].title.match(re);
      result.push(matches? matches.length : 0);
    }
    alert(result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Regular Expression for matching patterns say example in the follwoing example
How can I count the number of elements in an array, because contrary to
Can anyone explain: Why the two patterns used below give different results? (answered below)
I'm completely new to OOP PHP and currently reading PHP Objects, Patterns and Practice.
First, the formula I'm currently using: =countifs('page1'!AF:AF,$L6,'page1'!AA:AA,=&RIGHT(M$2,3))+countifs('page1'!AF:AF,$L6,'page1'!AB:AB,=&RIGHT(M$2,3))+countifs('page1'!AF:AF,$L6,'page1'!AC:AC,=&RIGHT(M$2,3))+countifs('page1'!AF:AF,$L6,'page1'!AD:AD,=&RIGHT(M$2,3))+countifs('page1'!AF:AF,$L6,'page1'!AE:AE,=&RIGHT(M$2,3))+countifs('page1'!AF:AF,$L6,'page1'!AF:AF,=&RIGHT(M$2,3)) Alright, now, what I'm attempting to match
My question is: where do these patterns (below) originate? I learned (somewhere) that Python
I am having an issue with regexp in C#. I've been using theses patterns
Count the longest sequence of heads and tails in 200 coin flips. I did
if(count > 0){ for(var i= parseInt(start); i < parseInt(count); i++) { link ='<a href=/diabetes/ropimages/origpicdisplay.php?pid='+pid+'&rid='+i+'
TOPIC_COUNT_SQL = SELECT COUNT(*) FROM topics_topic WHERE topics_topic.object_id = maps_map.id AND topics_topic.content_type_id = %s

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.