Searching for users using JSON format

I have a unique code snippet containing a JSON database and an XMLHttpRequest object.

The user parameter in the function getUsers(user) is user input. I am trying to select a user from the database based on the search input value, but I'm unsure about setting the correct HTTP URL or creating a suitable search algorithm.

Currently, I can select a user using user.Name1, but I'm struggling with modifying it after the dot (.Name1) so that it matches the input value.

For example: user. + "input value". I'm having difficulty figuring this out.

Answer №1

It seems like you're looking to access it using square brackets: user[userValue], with userValue representing your input variable.

Answer №2

To retrieve an object, simply use the syntax user["Name1"]. You can also dynamically access object properties with a variable like so: user[input_value_variable]

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

Issue encountered when utilizing ngResource in factory: unable to choose JSON index

ngResource in a factory is functioning properly, but unfortunately, it is only able to select the index of the JSON. However, it is also possible to bind the same variable $scope.resultItems. The console log appears as follows ...

Setting a default value for NULL property in TypeScript

Trying to establish a default value for all NULL objects has been quite the challenge. The current code looks like this: private setDisplayAmount(summaries: summary[]): void { summaries.map(t => { // performing some operations, and then... ...

Having trouble with jQuery UI draggable when using jQueryUI version 1.12.1?

Currently, I am diving into the world of jQuery UI. However, I am facing an issue with dragging the boxes that I have created using a combination of HTML and CSS. My setup includes HTML5 and CSS3 alongside jQuery version 1.12.1. Any suggestions or help wou ...

Eliminate all elements marked with a particular class when the user clicks outside of a

I am currently building upon a project that I previously started here. Essentially, what I'm doing is dynamically generating tooltip popups that appear next to a link when it is clicked. However, I now need these tooltips to close when any click even ...

Effective ways to engage with a window that is supervised by a different controller?

Although the question may appear vague initially, I struggled to find a better way to convey my idea. Let me elaborate on it in detail. In my SPA application, I have MasterController connected to the <html> tag. This MasterController consists of all ...

Incorporating interactive elements into nested forms via AJAX

Recently, I've been following and implementing the railscasts related to nested model forms on my application: 196-nested-model-form-part-1 and 197-nested-model-form-part-2. However, as I do not have a pro account, I am unable to access the updated ep ...

No search results found for Mongoose text search query

Despite using Mongoose 5.7.8 for my app, the text search feature is not yielding any results. Below is a schema/model example: import mongoose, { Document, Schema } from 'mongoose'; import { Moment } from 'moment'; import { IUser } fr ...

FastAPI's performance with processing large JSON requests is somewhat sluggish

My service handles large JSON requests and responses, ranging from ~200Kb to ~300Kb in size. Even without any processing done on the JSON data, the full round trip still takes around 30-40 milliseconds, even when testing locally on my own machine. Below i ...

`Finding it difficult to halt the spread of events in reactJs`

One of my conditions involves a simple dropdown menu: handleDropdown = (e) => { if (e.type === "focus") { console.log("inside dropdown focus"); this.setState({ dropDownDis: "block" }) } else if (e.type === "blur") { console.lo ...

The issue of "window is not defined" persists when using P5.js with Next.js, even

How can I import a component with a logo created using p5.js when encountering the error: window is not defined I researched solutions and discovered that within useEffect, the component will only mount once the window object becomes accessible. To test ...

In the Sandbox, element.firstChild functions properly, but it does not work in the IDE

Encountered an issue that has me puzzled. To give you some context, I attempted to create a native draggable slider using React and positioned it in the center of the screen, specifically within my Codesandbox file. The code snippet I utilized is as follow ...

Tips for embedding query values within a mongoose query

I have a database in MongoDB that contains an array with company names. I need to remove a specific element from the array based on its position. So, I crafted a query to achieve this. { company: [ {name: "exist"}, {name: "cool"}, {name: "h ...

What is causing my React-Testing Library queries to not work at all?

In my current project, I am using Jest along with Testing-Library to create UI unit tests. One issue that I encountered was that the components were not rendering on the DOM. After some investigation, I found that the main culprit was a component called & ...

Pass SASS/SCSS variables to Javascript without the need to export them to CSS files

Context Let's take a look at the _variables.scss file below: /* Setting up color variables */ $white: #fff; $black: #000; $grey: #ccc; // and so on... // Export the color palette for Javascript accessibility :export { white: $white; ...

Managing React state with custom objects

We are currently utilizing a react table component that requires selections to be maintained across different pages. To achieve this functionality, we have implemented a Map to store the selected rows and a custom class named Selections to manipulate these ...

Establishing the preset values for Material-UI toggle button group

I utilized the Material UI library to implement a button toggle widget for selecting options. Check out my codesandbox project here - https://codesandbox.io/s/50pl0jy3xk The user can interact by choosing a membership type: adult, child, or infant. Option ...

What is the best way to utilize JSON data in React components?

I am looking to showcase a collection of icons similar to what I saw on this particular website. Within my JSON data, I have stored both the family and name values for these icons. What I aim to do is map this JSON data in order to pass the family and nam ...

jQuery Each Loop failing to retrieve data during iteration

Encountered a peculiar issue while working with an each loop. The situation may seem a bit tangled but I'm constrained to manipulating the code with jQuery due to it being part of a larger framework that can't be modified. As a way to simplify t ...

Webpack attempts to duplicate files prior to compilation but I am anticipating the opposite outcome

I needed the copy plugin to run after compilation, which seemed like the logical order. However, I found myself having to compile using webpack twice every time in order to get the fresh version on production. It wasn't until later that I realized it ...

Troubleshoot the reason behind the malfunctioning Console log on the website

I have been troubleshooting why console.log is not printing anything. I have tried defining and enabling debugger mode, but nothing seems to work. https://i.sstatic.net/5clXf.png Check out the website here: Any suggestions on how I can resolve this issu ...