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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:02:17+00:00 2026-06-13T21:02:17+00:00

I have a JSON-encoded PHP array: <script> var registeredEmails = <?php echo(json_encode($emails)); ?>; </script>

  • 0

I have a JSON-encoded PHP array:

<script>
var registeredEmails = <?php echo(json_encode($emails)); ?>;
</script>

To check that this works, I do this:

console.log(registeredEmails);
// this outputs: ["john@domain.com", "mary@domain.com"]

And now I would like to iterate through that JSON and test a certain string against all the strings it contains.

for (var email in registeredEmails) {
    if (registeredEmails.hasOwnProperty(email)) {

        var duplicate = registeredEmails[email];

        console.log(duplicate + ' is typeof: ' + typeof(duplicate));
        // this outputs: john@domain.com is typeof: string

        //  $(this).val() is a string from somewhere else
        if (duplicate.test($(this).val())) {
            // we found a match
        };
    }
}

As I understand it, the test() method tests for matches on strings. I’ve tested to make sure that my variable duplicate is a string, but apparently it’s still an object. I’m given the following JS error:

Uncaught TypeError: Object john@domain.com has no method 'test'

Why is that?

  • 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-13T21:02:18+00:00Added an answer on June 13, 2026 at 9:02 pm

    test() is a method of the RegEx object, not String.

    Your best bet would probably be to use String.search() instead. You could also probably use String.indexOf() if you’re not trying to use Regular Expression matching.

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

Sidebar

Related Questions

I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second
I have a php script that outputs json data. For the purposes of testing,
I have three PHP arrays that I've encoded with json... extra PHP code has
Basically I have a php script located on a sever that generates a JSON
I have a function that returns json (networks_function.php builds up some arrays and encodes
i have a php function which returns a random json encoded color <?php function
So I have a $.post , that returns some json_encode($array); $array is one dimensional,
I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
I have index.php like this: <script type=text/javascript src=jquery-1.4.2.js></script> <script type=text/javascript src=ajax.js></script> <a href='one.php' class='ajax'>One</a>
Could not convert or access JSON object from PHP json_encode <?php $f_array = array();

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.