Searching for a specific key and its corresponding value within an Object Literal (JSON string / object) is necessary

After reading up on JSON objects , I am now trying to locate the value associated with a specific KEY, which may be null, no or yes.

The KEY in question is "f03eb90f-6b5e-4b26-bd9f-bad788b7edac" and I want to retrieve its value

You can find the Fiddle here: https://jsfiddle.net/4vse3uw1/

I attempted to create an array, push the data into it, and then run a for loop to search for the desired key:

var arr = [];
arr.push(d)
console.log(arr)

for (props in arr) {
    if (arr[props] == "f03eb90f-6b5e-4b26-bd9f-bad788b7edac") { 
       //doSomething(); 
      console.log(props)
    }
}

Following that step, I tried:

for (var i = 0; i < arr.length; i++)
{
   console.log(i)
}

The variable 'd' contains several JSON entries with keys and values. Here is a snippet of what's included:

Answer №1

Upon inspection, it appears that your array consists of only one element that happens to be a large object. You can simply access the desired property within that object.

var data = [{"00ee9adf-1525-4d1c-a4d7-54f43fa65ae4":"No","0194abfe-8f24-485f-a129-03011ac930a6":"No","01f97094-7f5f-4db5-8fbf-735604b5d76f|Sub1":"99",...

Answer №2

    // Let's suppose you have all results stored in this array
    let array = // big array containing results

    // This code will search for all the objects in the array 
    // and create a new array with all the extracted values :)
    let allValues = array.map(object => {
      return object["f03eb90f-6b5e-4b26-bd9f-bad788b7edac"]
    })

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

Generating a JSON string directly from the results of a database query

I am attempting to generate a JSON object based on the results of a database query. Here is an example of what I am trying to achieve: json_obj= { '1': 'test_1', '2': 'test_2', &apos ...

Utilize the power of Jolt to seamlessly transform and convert straightforward flat JSON data into intricate nested JSON

Looking for help with transforming flat json data into nested json using jolt. I'm new to jolt and here is the input I'm working with: { "id": "LIKKI MOSORU", "aff_id": "WOOD", "aff_name": "WOOD-LOVE", "aff_desc": "WOOD INC.", "aff_corrltn_ ...

Dropdown Placement Based on Button Click

Looking to create an interactive dropdown menu with the Alloy UI Dropdown Component that appears when a user clicks on one of four buttons. The goal is for this dropdown to be positioned to the left of the clicked button. var toolsDropdown = new Y.Dropdow ...

What is the best way to bring in styles to a Next.js page?

I am facing an issue with my app where I have a folder called styles containing a file called Home.module.css. Every time I try to include the code in my pages/index.js, I encounter the same error message saying "404 page not found.." import styles from & ...

Exploring the Syntax of React

As I am still fairly new to react and have a basic understanding of Javascript. Following a tutorial, everything was clear until the instructor moved forward. Now, when I go back over the material, I find myself struggling to grasp this concept. render() ...

Exploring unescaped XML for handling unicode characters

Currently tackling the challenge of parsing some XML that is not properly formatted. The XML file contains un-escaped ampersands, which goes against the standard rules for XML files. My goal is to extract unicode formatted phrases from this XML file whil ...

JavaScript Decoding JSON with varying identifiers

The JSON data provided contains information about different types of vehicles, such as cars, buses, and taxis. { _id:"7654567Bfyuhj678", result:{ CAR:[ [ "myCar1", 12233 ], [ ...

Retrieve data from a massive JSON file by reading a single row and its attributes using JsonTextReader

My current task involves extracting data from a large (1.2GB) JSON file without the need to define a class beforehand. I specifically aim to access nested values using a single string path such as: facilities.totalSize.value In light of these revised requ ...

Is there a way to determine the file size for uploading without using activexobject?

Can the file size of an uploading file be determined using Javascript without requiring an ActiveX object? The solution should work across all web browsers. ...

Struggling to decode JSON data in Swift using SwiftyJSON

I am having trouble populating an array using SwiftyJSON to parse a JSON file. I am also unsure if my request process is correct. The JSON format should be simplified as follows: A dictionary with a "string" key and a value of an array of dictionaries, fo ...

Verifying a user's name when navigating a route

Hey everyone, I've been working on this project for the past 3 hours and could really use some help. I created an express webapp with an admin page. The register and login functionalities are all set up using passport. I have a function to check if th ...

Dynamic class/interface in Typescript (using Angular)

Is there a way to achieve intellisense for an object created with a dynamic class by passing parameters? Here is the code snippet: Main: let ita: any = new DynamicClass('ITA'); let deu: any = new DynamicClass('DEU'); The DynamicClass ...

What is the standard root directory in the "require" function's context?

After spending hours struggling to set up a simple "require" command, I've come to the conclusion that var example = require("example") only works if there's an example.js file in the node_modules directory of the project. I'm encountering ...

How can Laravel allow for multiple resources to have more than one accessor attached to them?

I'm facing an issue while trying to utilize an accessor on a model to determine whether a relationship exists. My User model: class User { protected $appends = ['has_profile']; public function profile() { return $this->ha ...

The jQuery script is functioning flawlessly in one specific direction

Currently, I am utilizing a basic script to alter the color of elements based on the div being hovered over. While this works smoothly in one direction down the line, when trying to reverse order and backtrack, the colors do not function as intended. The ...

Transferring the output of a function to a different state

My current challenge involves sending data from one controller to another within an Ionic application. Despite creating a service for this purpose, I am still unable to share the data successfully. The send() function in MainCtrl is meant to pass the data ...

Capture locations from Google Maps

What is the best method to extract all addresses, along with their latitude and longitude, for a specific city (such as Bangalore) from Google Maps using PHP/JavaScript and store it in a MySQL table? I urgently need assistance. Thank You ...

The ul cannot be hidden if there are no li elements within it

Currently, I am attempting to hide the unordered list (ul) on a specific page using AJAX due to certain sections of the site being Ajax-based. <ul class="sub-nav-20-m" id="filtersList_m"> </ul> Below is the code that I hav ...

Saving JSON data retrieved from the server into an array in Angular 2

Using a nodejs server to retrieve data from an SQL database has been challenging. I attempted to store the data in taches, which is an array of Tache : getTaches(): Observable<Tache[]> { return this.http.get(this.tachesUrl) .map(response => ...

Each time `fs.writeFile` is invoked, it initiates a fresh line

Every time this code is run, I want it to create a new line of data instead of overwriting the previous one. For example, if it's executed once, it would display: Checked Status: ONLINE. However, upon subsequent runs, it should add another line direc ...