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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:28:41+00:00 2026-06-07T00:28:41+00:00

How do I transform this JSON object: context:{#text:[Most Visited Pages , Hall Residents Advanced

  • 0

How do I transform this JSON object:

"context":{"#text":["Most Visited Pages  "," 
Hall Residents Advanced Components"," Clerk"],"highlight":["City","City"]}

into:

Most Visited Pages <highlight>City</highlight> 
Hall Residents Advanced Components <highlight>City</highlight> Clerk

by using Javascript?

I have tried:

 function highlightContext_22(context) {
      var highlighted;
      $.each(context['#text'], function(key, val) { 
           highlighted += val + val.highlight;
      });
      return highlighted;
 }

Output is:

undefinedMost Visited Pages undefined 
Hall Residents Advanced Components undefined Clerkundefined
  • 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-07T00:28:42+00:00Added an answer on June 7, 2026 at 12:28 am

    The property val.highlight does not exist, which is why you’re getting undefined. Your object has an array value for the key of #text. The highlight key is a separate property and thus cannot be accessed in the current context.

    The solution below corrects the refence to allow the highlight value to be referenced. I’ve added additional indicators for illustrative purposes.

    JavaScript:

    var obj = {
        "context": {
            "#text": [
                "Most Visited Pages  ",
                " Hall Residents Advanced Components",
                " Clerk"
            ],
            "highlight": [
                "City",
                "City"
            ]
        }
    };
    
    var result = [];
    var data = obj.context;
    
    for(var i=0; i < data['#text'].length; i++){
        result[i] = data['#text'][i] + (data.highlight[i] ? '<highlight>' + data.highlight[i] + '</highlight>' : '');
    }
    
    document.getElementById('result').innerHTML = result.join('');
    
    alert(document.getElementById('result').innerHTML);
    

    Demo: http://jsfiddle.net/Wv3vH/

    NOTE: the above data attempts to compare two arrays of equal length. Since the #text array is one larger than the highlight array, there is an undefined value which is not displayed due to the boolean logic to check if the value exists.

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

Sidebar

Related Questions

Let's say i have this json data. How to transform the tags to a
I need to transform my nested sets structure (mysql) into json for this spacetree
Wikipedia's Wavelet article contains this text: The discrete wavelet transform is also less computationally
Under this link : http://dev1.gecoloco.com/rte/done_json.php I have a json-like object, that I'm operating on.
I want to receive a JSON object using Ruby. I've written this: require 'sinatra'
This is my Xml file.i want to transform this xml file into another customized
Given the following sequence: normal %(b)BOLD% normal I want to transform this into the
I'd like to transform an URL like this http://www.mydomain.com/it/archive.php=321123 in one like the following
Any idea why this code: extern C __declspec(dllexport) void Transform(double x[], double y[], int
This code: (self is a subclass of NSView) rotate = [CABasicAnimation animationWithKeyPath:@transform.rotation.z]; rotate.duration =

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.