Ways to extract information from a text

I have a massive string, divided into two parts that follow this pattern:

     {\"Query\":\"blabla"\",\"Subject\":\"gagaga"}",   
     {\"Query\":\"lalala"\",\"Subject\":\"rarara\"}",  

and so on... (thousands of lines)

My goal is to create a variable that contains these values:

data= "blabla,gagaga","lalala,rarara",....

This is the code I'm using but it's not functioning correctly:

var contentss = JSON.stringify(allFileGenesDetails1);
data="";
var Query1="";
var Subject1="";
// Parse the data

var contentEachLines = contentss.split("\n");
for (var jj = 0; jj < contentEachLines.length; jj++) {
var lineContent = contentEachLines[jj].split("\t");

var divided = lineContent[jj].split(",");
Query1= Query1+ [divided[0]];
Query1 = Query1.replace(/Query|:|{|"|\|/gi, "");

Subject1=Subject1+ divided[1];
Subject1 = Subject1.replace(/Subject|:|{|"|\|/gi, "");
data=data+"'"+ Query1+","+Subject1 +" ' " +"," ;

Answer №1

Give this a try:

let fileGenes = JSON.parse("[{\"Query\":\"blabla\",\"Subject\":\"gagaga\"},{\"Query\":\"lalala\",\"Subject\":\"rarara\"}]");
let output = "";
for(let i = 0; i < fileGenes.length; i++) {
    if((i+1)==fileGenes.length)
        output += fileGenes[i].Query+","+fileGenes[i].Subject;
    else
        output += fileGenes[i].Query+","+fileGenes[i].Subject+",";
}
console.log(output);

Check out the code here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to execute TypeScript class methods in asynchronous mode without causing the main thread to be blocked?

Creating an app that retrieves attachments from specific messages in my Outlook mail and stores the data in MongoDB. The challenge lies in the time-consuming process of receiving these attachments. To address this, I aim to execute the task in a separate t ...

How come AngularJS $onChanges isn't able to detect the modification in the array?

What is the reason behind Angular's failure to detect changes in an array, but successfully does so after changing it to null first? In my AngularJS component, I utilize a two-way data binding to pass an array. The parent component contains a button ...

Guide to custom sorting and sub-sorting in AngularJS

If I have an array of objects like this: [ { name: 'test1', status: 'pending', date: 'Jan 17 2017 21:00:23' }, { name: 'test2', sta ...

There are two references to an object, but even if one of them is modified, the second reference continues to show the

During my attempts to troubleshoot an issue in a JS plugin, I noticed that one variable was sometimes affecting another and sometimes not. In order to investigate further, I added the following code: var a = $('#w3').data('fileinput'). ...

A guide to building your own live HTML editing tool

I'm currently developing a PHP website that allows users to enter text into a textarea, and have the input displayed in a table in real time for a preview of the result. I am seeking guidance on how to make this feature possible. I have come across w ...

What is the difference between TypeScript's import/as and import/require syntax?

In my coding project involving TypeScript and Express/Node.js, I've come across different import syntax options. The TypeScript Handbook suggests using import express = require('express');, while the typescript.d.ts file shows import * as ex ...

Step-by-step guide on utilizing the material-ui AutoComplete feature to filter a table by selecting a key from a list and manually entering

I'm working on developing a filtering system similar to the AWS Dashboard, where users can select a filter key like instance state, which then displays the key in the input field and allows the user to enter a value to search for. I'm attempting ...

Leverage the hidden glitch lurking within Vue

While working with SCSS in vue-cli3, I encountered a strange bug where using /deep/ would result in errors that I prefer not to deal with. Code Running Environment: vue-cli3 + vant + scss CSS: /deep/ .van-tabs__content.van-tabs__content--animated, .va ...

Properly managing mouseover events on a flipped div: tips and tricks

I created a div that flips when clicked using some HTML and CSS code. It works perfectly in Firefox 39 and Chrome 43. Here is the markup: <div class="flip-wrapper flippable-wrapper" id="fliptest-01"> <div class="flip-wrapper flippable ...

Executing jQuery post request on a div loaded via ajax

I'm facing a challenge with my webpage. I have a section where the content of a div is loaded via ajax. This div contains forms, and after submission, it should update to display the new content without refreshing the entire page. Can anyone guide me ...

What is the best way to retrieve a list of customers within a specified date range?

How can I retrieve a list of customers within a specified date range? My frontend react app includes starting and ending date pickers, but I'm unsure how to query the data using mongoose in my express app. Below you'll find my mongoose model and ...

Discover the best locations within the city using Google's API to search by category

Users will choose a city and a type of place. The desired output is a Google Map showing all places in that city with the selected category. I'm looking to achieve this using Google Maps APIs. So far, I've tried using the Places API but it onl ...

Struggling to display the Three.js LightMap?

I'm having trouble getting the lightMap to show on my mesh. Here's the code I'm using: loader.load('model.ctm', function (geometry) { var lm = THREE.ImageUtils.loadTexture('lm.jpg'); var m = THREE.ImageUtils.loadT ...

I am attempting to invoke a JavaScript function from within another function, but unfortunately, it does not seem to be functioning

I encountered an issue that is causing me to receive the following error message: TypeError: Cannot read property 'sum' of undefined How can this be resolved? function calculator(firstNumber) { var result = firstNumber; function sum() ...

Experiencing difficulties in transmitting multipart form data from React to Express Js accurately

I am facing an issue with uploading files using Dropzone and sending them to a Java backend API from React JS. In this scenario, React sends the document to Express backend where some keys are added before forwarding the final form data to the Java endpoin ...

When I try to use the mongoose find() function, I am receiving a Promise status of <Pending>

I recently developed a function to retrieve the list of all products stored in MongoDB using mongoose. However, when trying to log this information, I am unexpectedly getting a Promise instead. Below is the relevant code snippet: router.get('/', ...

Interactive image sliders in a Netflix-inspired style with live previews on hover, fully compatible with Bootstrap framework

I'm looking for suggestions on Twitter Bootstrap compatible jquery plugins that can create a Netflix-style continuously scrolling image carousel with mouse-over functionality. I've tried the carousel included in the Bootstrap JS library, but it r ...

Managing multiple sets of radio buttons using the useState hook

Within my renderUpgrades-function, I handle the options of an item by including them in radio-button-groups. Each item has multiple options and each option has its own radio-button-group. Typically, a radio-button-group can be managed using useState, wit ...

Verify whether the items within the ng-repeat directive already contain the specified value

I am facing an issue with displaying a JSON string of questions and answers in ng-repeat. The problem is that I want to display each question only once, but show all the multiple answers within ng-repeat. {Answer:"White",AnswerID:967,answer_type:"RADIO",f ...

In IE7, the string comparison in jQuery exhibits unique behavior

When using the following code snippet with a jQuery UI autocomplete element (#search), it works as expected in Firefox, Chrome, and other browsers, always returning true for the selected element. However, Internet Explorer 7 does not behave as expected. $ ...