Using Javascript to search and refine a JSON field based on a specific string

I am attempting to use JavaScript to filter a JSON field based on a string input. Essentially, I have a search box and a simulated JSON response. When I type letters into the search box, an ajax call should filter my simulated response based on the input string so that I can display the result.

My search box and function to make the ajax call with the simulated response are working correctly. However, I am encountering difficulties when it comes to filtering.

var res = response.filter(function (i, n) {
    return String(n.Name).toLowerCase().indexOf(String(srt).toLowerCase()) === 0;
});

Below is the simulated JSON response:

[{ "Name": "ALICE", "Close": 7.12, "UpDown": 1 }, { "Name": "MICHAEL", "Close": 110.78, "UpDown": 1 }]

n.Name is returning undefined. As a result, the res contains objects with undefined values. In this scenario, if I enter und, for instance, all elements are displayed; but if I enter any other value, none of the elements pass the filter.

Why is this happening and how can I resolve this issue?

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

The not-found.js file in Next.js is displaying an empty page rather than showing a 404 error message

My current project involves using Next.js v13.4.19 with the app router mode. However, I seem to be facing an issue with the not-found.js page located in the app folder. Whenever a non-existing route is accessed, it does not render a 404 page as expected. ...

Using mui-datatables to display an array of objects

Seeking help from users of mui-datatables. While it successfully handles data in the form of an array of strings, there is an issue when trying to load an array of objects resulting in the following error: bundle.js:126379 Uncaught (in promise) TypeEr ...

It looks like everything is running smoothly, but it seems like the ReactDOM.render() method is missing in action

I'm currently diving into the world of React.js and eager to build my knowledge from the basics upwards. While delving into the documentation, I stumbled upon the utilization of ReactDOM.render(element, Document.getElementById("root")), whi ...

Are ES6 arrow functions not supported in IE?

When testing this code in my AngularJs application, it runs smoothly on Firefox. However, when using IE11, a syntax error is thrown due to the arrows: myApp.run((EventTitle, moment) => { EventTitle.weekView = event => \`\${moment(event.s ...

Using JQuery: Executing a callback function at the end of each loop following the ajax call

How can I implement a callback for each loop iteration after an AJAX call is completed? Here is my code: Scenario: Suppose I have 3 values - X, Y, Z. Initially, I take the X value, send it to Django views where I use the requests module to retrieve some ...

React function failing to utilize the latest state

I'm facing an issue with my handleKeyUp function where it doesn't seem to recognize the updated state value for playingTrackInd. Even though I update the state using setPlayingTrackInd, the function always reads playingTrackInd as -1. It's p ...

Retrieving information from a database by employing AngularJS with the assistance of PHP

I am a beginner in using AngularJS and I am trying to retrieve data from a database using PHP. Here is the code I have tried: <html> <head> <script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2 ...

How to smoothly fade out content when hovering over a menu item in HTML<li> tags

Hi there, I have encountered a problem and could really use your assistance. I am attempting to create a menu that displays content when you hover over an li tag. The first content should always be visible when hovering over the first li option or if no l ...

Implementing a long press feature for a stopwatch in React

I'm facing a dilemma with this particular issue. Before reaching out here, I scoured the community and found numerous solutions for handling long press events in React, but they all seem to focus on click button events. Currently, I am devising a sto ...

Executing PHP scripts in Javascript to monitor active online users: identifies individuals who are currently not authenticated

I am currently developing a basic admin panel and looking to allow logged in users to view other active users. To achieve this functionality, I have set up a sessions MySQL table containing active session data (logged in users) alongside a PHP file that up ...

What is the best way to submit a Redux Form only if there have been changes made to any of the fields

I'm currently using Redux Form version 7.1.2, and I have a form that submits data when the user clicks the submit button. In the function assigned to handle the submission, I perform an action. However, I only want this action to be executed if there ...

Looking to retrieve the text content of an element using jQuery?

My goal is to use jQuery mobile to transfer a user to a linked page when they click on an <li> element, and then display an alert with the text of the list element they clicked. However, my current implementation only shows an empty alert box. < ...

Combining the jquery-UI slider functionality with the canvas rotate() method

Is there a way to rotate an image using html2canvas plugin and jQuery UI slider? I am new to programming and need some guidance on how to achieve this feature. Here is my current progress: http://jsfiddle.net/davadi/3d3wbpt7/3/ ` $("#slider").slider({ ...

Can a VS Code theme extension be designed using JavaScript or TypeScript rather than JSON?

Currently working on a VS Code theme extension, I am interested in exploring the possibility of using JavaScript or TypeScript files instead of a JSON file. The idea of having all the theme information crammed into one massive JSON file feels disorganize ...

Enhancing user experience with AngularJS: Harnessing ng-Click for seamless task management on display pages

I'm struggling with my TodoList in AngularJS. I need help creating the ngClick function for the "addTodo" button. My goal is to send the entire form data to another page where I can display the tasks. Can someone guide me on what needs to be added to ...

The split function in JavaScript is exhibiting some unusual behavior

There is something wrong with my code challenge1 = () => { var data = fs.readFileSync('santa21.txt', 'utf8'); data = data.toString(); dataSplit = data.split(' ') console.log(dataSplit); }; challenge1(); The result of the ...

What is the best way to extract data from a JSON structure that is enclosed within two square brackets

I am facing an issue with parsing data from a JSON File that has two square brackets at the beginning. The JSON type is classified as 'list'. Despite searching for solutions on Stackoverflow, I couldn't find one that works for me. As someone ...

Keep appending numbers to a string without stopping

I have a task where I need to add digits continuously to a string. To achieve this, I started by removing the last character of the string and then adding digits starting from 1 in a sequence. Below is the code snippet for reference: using System; using S ...

Error message displayed for invalid date format in Material UI (dateTime picker) after form submission

I recently integrated the Material Ui DateTime picker into my form. However, upon submitting the form, I encountered the following error: Invalid Date Format Image In my React app, I am utilizing JSON Server to store data. Displayed below is the outpu ...

The array containing numbers or undefined values cannot be assigned to an array containing only numbers

Currently facing an issue with TypeScript and types. I have an array of IDs obtained from checkboxes, which may also be empty. An example of values returned from the submit() function: const responseFromSubmit = { 1: { id: "1", value: "true" }, 2: ...