Key within square brackets in a JSON array

I am dealing with a JSON array that includes a square bracket in the key, like this:

{
  "msg":"OK",
  "data":[
    {
      "nls!type":"NCR",
      "current":"Assign",
      "physicalid":"0FFE0001000009FC5BD6805C00001352",
      "attribute[custTitle]":"Title",
      "name":"181002",
      "description":""
    }
  ]
}

My question is, how can I access the value of "attribute[custTitle]" in JavaScript?

When attempting to retrieve arrData[i].attribute[custTitle], I am encountering an error stating that custTitle is not defined. However, I am able to access the other values in a similar manner without any issues.

Answer №1

give this a shot

const result = {
  "message":"Success",
  "info":[
    {
      "type":"NCR",
      "status":"Pending",
      "id":"0FFE0001000009FC5BD6805C00001352",
      "attribute[title]":"Title",
      "number":"181002",
      "details":"" 
    }
  ]
};

console.log(result.info[0]['attribute[title]']);

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

Error occurred while attempting to run 'postMessage' on the 'Window' object within GoogleTagManager

Recently, I encountered an error stating "postMessage couldn't be cloned". This issue seems to be affecting most of the latest browsers such as Chrome 68, Firefox 61.0, IE11, and Edge. Error message: Failed to execute 'postMessage' on &ap ...

Data disappears on the following line

Could someone please help me understand what's going on in these snippets of code and how I can resolve it? I am fetching data in the parent component's mounted function and updating its data. As a result, the child component receives the new ob ...

Trigger a modal to open based on a specific condition

I have successfully implemented a default modal from Materialize, but now I am looking to add a conditional opening feature to it. In my application, there is a countdown timer and I want the modal to automatically appear when the countdown reaches a certa ...

Validating group radio buttons that have been checked

I possess: <div class="group"> <input type="radio" name="myradio" value="1">a <input type="radio" name="myradio" value="2">b </div> <div class="group"> <input type="radio" name="two" value="3">a <input ty ...

Tips for correctly implementing JavaScript conditional statements

Upon running this jQuery (1.8.3) code, I consistently receive the "in" alert message even when the length is greater than 1. The purpose of my actions is to dynamically add elements to a menu while ensuring that the element does not already exist. Even a ...

Fullcalendar JS will easily identify dates with events, allowing users to simply click on those dates to redirect to a specific URL

When looking at the official example, we can see that the events are displayed in a typical calendar format: https://fullcalendar.io/js/fullcalendar-3.5.0/demos/basic-views.html Each event is listed in the calendar, and clicking on an individual event wi ...

Can someone provide guidance on how to validate a HEX color in Cypress?

As I dive into testing with Cypress, my lack of experience has become apparent. I am trying to test the background-color CSS property on a specific element, but running into an issue - everything is in RGB format behind the scenes, while I need to work wit ...

"Encountering an error with ExpressJS where it cannot GET a file, preventing access to other folders' content

My goal is to set up a simple server using expressJS to retrieve data for my Angular application. However, I've encountered an error that says 'Cannot GET/'. This is the code snippet of the webserver I attempted to create: var express = re ...

In JavaScript, the return statement is used to halt the execution of any subsequent statements

I encountered a situation where I need to stop the execution of the next function call if the previous function has a return statement. However, I noticed that even though there is a return statement in the "b" function below, the next function call still ...

Tips for extracting a nested key value from a JSON data structure

I am working with a PostgreSQL table CREATE TABLE IF NOT EXISTS account_details ( account_id integer, condition json ); The table contains the following data account_id condition 1 [{"action":"read","subject": ...

Error in TypeScript - Anticipated 1-2 arguments, received either none or multiple. Code Issue TS2556

While working in JavaScript, I had no issues with this code snippet. However, when I attempted to implement it in a TypeScript Project, an error surfaced. The problem seems to revolve around the fetch(...args) function call. const fetcher = (...args) =&g ...

What is the best way to create a dynamic JavaScript counter, like one that counts the world's population

Can someone guide me on creating a real-time JavaScript count-up feature that doesn't reset when the page reloads? Any tips or examples similar to would be much appreciated. Thank you! ...

Is there JSON data available to determine the overall attendance rate in percentage?

I have a set of attendance data for a specific student. Each subject is marked with a 1 if the student was present, and a 0 if absent on a particular date. I need assistance in calculating the total attendance based on this information... { " ...

Angular Nested Interface is a concept that involves defining an

Looking for guidance on creating a nested interface for JSON data like this: Any help is appreciated. JSON Structure "toto": { "toto1": [], "toto2": [], "toto3": [], } Interface Definition export interface Itot ...

It can be frustrating to have to refresh the page twice in order to see changes when utilizing the revalidate feature in Next

When I make the REST call to fetch data for my page using the code below: // src/app/page.js const Home = async () => { const globalData = await getGlobalData(); return ( <main'> <SomeComponent data={globalData} /> < ...

How can we reduce the size of a JSON object in Typescript before sending it to the client?

Currently, I am faced with a common challenge. I have a database object that is a standard JS object originating from a document database, and my goal is to transmit this object to the client. However, certain fields contain sensitive information that shou ...

Can a custom function be executed using setTimeout in Node.js?

I am currently facing an issue with stopping the execution of my code for 2 seconds so that all ongoing animations can finish. I am attempting to implement a delay using setTimeout in Node.js. Here is what I have tried: this.userActivity = function(a,b, ...

Node.js promises are often throwing Unhandled Promise Rejection errors, but it appears that they are being managed correctly

Despite my efforts to handle all cases, I am encountering an UNhandledPromiseRejection error in my code. The issue seems to arise in the flow from profileRoutes to Controller to Utils. Within profileRoutes.js router.get('/:username', async (r, s ...

Creating PDFs with barcodes using Node.js

Currently, I am utilizing https://github.com/devongovett/pdfkit to create PDF files easily. This can be achieved with a simple code snippet like below: app.get('/get-pdf', (req, res) => { const doc = new PDFDocument(); const filename = &ap ...

Challenges with using $.getJSON in Internet Explorer 8

Unfortunately, I am required to support IE8 and I am struggling to make a simple $.getJSON request work properly. Here is the code snippet: url = "http://www.somejson.com/data.json"; $.getJSON(url, function(data) { var funds = []; var benchmarks = [] ...