Javascript - finding data in a table

I am new to the world of programming and currently learning javascript. I have a table with 754 values in the format 000089/04/18/0601AX. I am looking to create a script that will generate another table containing values with /04/18. Any assistance with this would be greatly appreciated!

Answer №1

If your table is called myTable, you can extract any item from it that contains /04/18, such as 000089/04/18/0601AX or 000104/04/18/0801DA and so on, but not 000089/04/17/0601AX or 000089/03/18/0601AX

Here is the script to achieve this:

function findValue(searchVal, table){
    var result = []
    var key
    //iterate through the table named list
    for (key in table)
    {
        //check if value searchVal is included in current item of the table
        if (table[key].includes(searchVal)){
            //if yes, add it to the result array
            result.push(table[key])
        }
    }
    //return the new array with matching values
    return result
}

var filteredTable
filteredTable = findValue('/04/18', myTable);

All lines starting with // are comments and can be removed.

findValue(arg1, arg2) is a function with two parameters: arg1 is the value you want to check for in the list arg2 is the list you want to search through.

With this function, you can search for any value in a table.

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

Prevent the line break from going beneath the ::before pseudo element

p::before { content: "1. "; } p { width: 200px; } <p>This is an example of a long text that requires a line break: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam ...

Creating a two-dimensional perspective in Three.js

I am new to utilizing three.js and I am currently attempting to create a 2D visualization using these 3D tools for layered sprites. I am looking for guidance on the arguments for PerspectiveCamera() and camera.position.set(). I have received some helpful h ...

Error encountered when processing a PUT request for a node causing a

After receiving minimal views and replies on a similar question I posted last night, I am reaching out again in hopes of resolving my issue. For the past two days, I have been struggling to fix this problem and progress with my project! If you are interes ...

Creating a custom Angular filter that leverages the power of $http - a

I want to make a retrieval request using $http in AngularJS and then display the obtained result on the front-end. To achieve this, I'm using {{ URL-STRING | iframely }}. 'use strict' angular.module( 'iframely', [] ).filter( &ap ...

Innovative Functions of HTML5 LocalStorage for JavaScript and TypeScript Operations

Step-by-Step Guide: Determine if your browser supports the use of localStorage Check if localStorage has any stored items Find out how much space is available in your localStorage Get the maximum storage capacity of localStorage View the amount of space ...

What is the best way to create a React filter utilizing the Autocomplete component from MaterialUI and incorporating state management?

I am currently in the process of creating a filter using the Autocomplete component from MaterialUI. As I select options from the dropdown menu, several things are happening: The Autocomplete automatically adds the selected options to the Chip Array. The ...

Is there a way to compress my JavaScript and CSS files using gzip?

I am facing an issue with gzipping a prototype library. I have no idea how to go about it, where to start, and how it actually works. I tried looking at some tutorials but unfortunately, they weren't very helpful... So here's the setup: I have ...

The tabs are visible in the drawer, but the transition is not occurring

I am a beginner when it comes to using material ui. After clicking on advanced sports search, a drawer pops up. I have been trying to incorporate tabs in the drawer, but every time I click on tab two, the drawer closes. In reality, it should switch between ...

Table cell featuring a status menu created with Material UI DataGrid

I'm looking to include a column called "Filled Status." Although I've checked the documentation, I can't quite figure out how to do it. It seems like I may need to use renderCell when setting up the column, but I'm not sure how to make ...

Trigger the show.bs.modal event prior to the parent event being called

In my Bootstrap website (built with Bootstrap 4), I have a button that triggers a modal and transfers the data from the button to the form inside the modal using the following function: $('#exampleModal').on('show.bs.modal', function ( ...

Utilize Office Scripts to update values across numerous worksheets

Looking for ways to improve the performance of this script, as it currently takes 45 seconds to run. Any ideas? function main(workbook: ExcelScript.Workbook) { try { const sheets = workbook.getWorksheets(); for (let sheet of sheets) { const break ...

Progressive Web App (PWA) default start URL

I am currently facing an issue with my Vue app, which is also a Progressive Web App (PWA). While the PWA functions correctly as planned, I realized that I am using generic paths for my web application. This means that in order to access the correct page, ...

When trying to update a MySQL database, the ampersand is appearing as &amp;amp; instead of the expected &

Currently, I am in the process of creating an administrative section that will allow for easy management of information displayed on the main website. This section will enable users to add, update, and delete content using just one page. Most of my script ...

JQuery was partially activated

Having just started using JQuery, I wanted to create a button that can dynamically change the colors defined in the CSS between blue and red when clicked, as well as updating the text displayed on the button. The draggable() function is working properly, ...

React higher order component (HOC) DOM attributes are causing the error message 'Unknown event handler property' to be triggered

I recently created a Higher Order Component (HOC) using recompose, but I'm encountering a React Warning every time the props are passed down. Warning: Unknown event handler property `onSaveChanges`. It will be ignored. All my properties with a speci ...

Stop vertical scrolling in browser when a link with the href "#divID" is clicked

At the center of my webpage, I have a small menu. When you click on a button, it should smoothly scroll horizontally to the chosen content. However, when clicking, the entire window scrolls, making the menu disappear from view. The issue is illustrated her ...

Is it possible to create 3D maps using a combination of Three.js and leaflet

Creating 3D maps with Leaflet can be quite the challenge, but I'm determined to make it happen. My goal is to display buildings in a three-dimensional perspective using Leaflet as my foundation. I've dabbled with OSM Buildings, but they fell sho ...

Sending a Thunk to the store using Typescript

Within my primary store.ts file, the following code is present: const store = createStore( rootReducer, composeWithDevTools(applyMiddleware(thunk)) ); store.dispatch(fetchUser()); Upon initial rendering, an action is dispatched to fetchUser in ord ...

What could be causing the issue of TinyMCE 5 not displaying formatted HTML on both the website page and in the database?

Seeking assistance as a beginner programmer. I'm currently working on my first coding project and encountered an issue. In need of a text editor, I incorporated TinyMCE 5. Utilizing JavaScript and mongoDB for coding purposes. This is how I included ...

making changes to the JS node dependency package results in a syntax error during compilation process, particularly within the npm/Vue.js environment

After creating a Js library and encountering stability issues and a few bugs that need fixing, the dilemma of developing a library arises when HMR does not work with dependencies. Here's a possible solution: To start, create a new Vue project using ...