Finding elements in an array based on a specific string contained within a property

I am currently working on filtering JSON data to specifically search for job roles that begin with a particular string.

The structure of the JSON is as follows :

"periods": [
        {
            "periodName": "Week1",
            "teamName": "Tango",
            "roleName": "SoftwareEngineerII",
            "roleExperience": "2",
            "id": "cc1f6e14-40f6-4a79-8c66-5f3e773e0929"
        },
        ...
    ]

My goal is to extract roleNames starting with "Software" in order to list all Software Engineers and filter out other roles.

I am uncertain about how to implement a "starts with" or "contains" function in this scenario.

Answer №1

Have you ever wondered how to efficiently filter an array based on a string property value? One method is using regular expressions to check if a string contains another string:

var str = 'SoftwareEngineerII';
if (str.match(/^software/i)) {
    // it starts with 'software'
}

To apply this concept as a filter predicate, you can use the following code snippet:

var query = Enumerable.From(data.periods)
    .Where("!!$.roleName.match(/^software/i)")
    .ToArray();

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

React not displaying wrapped div

I am facing an issue with my render() function where the outer div is not rendering, but the inner ReactComponent is displaying. Here is a snippet of my code: return( <div style={{background: "black"}}> <[ReactComponent]> ...

Obtaining information from node.js module to the server.js script

I am attempting to extract data from a function within a node module, which returns a JSON object. My goal is to display this JSON object in a router located in my server.js file. This is how I am trying to export it: // Function Export exports.g ...

Tips for sharing content within an iframe

Despite my efforts to find a solution, I have been unable to come across one that aligns with my specific situation. I currently have a form for inputting person data. Within this form, there is an iframe containing another form for adding relatives' ...

Only trigger the onclick event once

Can anyone assist me with a function? The onclick event only triggers once. launchTagManager: function(id) { console.log(document.getElementById('metadata_field_multiple_text_701889_options['+id+']')); document.getElementById( ...

looking to display the latest status value in a separate component

I am interested in monitoring when a mutation is called and updates a status. I have created a component that displays the count of database table rows when an API call is made. Below is the store I have implemented: const state = { opportunity: "" } ...

How can I change the attributes of icon().abstract.children[0] in the fontawesome-svg-core api?

The issue at hand: The icon() function within the fontawesome-svg-core API is setting default properties for SVG children elements that require custom modifications. My objective: The outcome of the icon() method is an object with an "html" property, co ...

Next.js: How to retrieve route parameter within getServerSideProps

I need to retrieve data from my Supabase table using the ID provided in the URL slug, for example localhost:3000/book/1, and then display information about that specific book on a page built with Next.js. Table https://i.stack.imgur.com/t5z7d.png book/[ ...

How can I duplicate or extract all the formatting applied to a specific text selection in Ckeditor?

I am currently utilizing CKEditor version 3.6 within my Asp.net MVC 3 Application. One of my tasks involves creating a Paint format option similar to Google Docs. I am looking to integrate this feature into CKEditor. Is there a way in CKEditor to transfe ...

What methods can be used to keep track of Ajax requests?

Within my HTML page, I have implemented multiple JQuery Ajax calls using methods like get and post. I am interested in monitoring the states of these ajax calls without relying on the "success" or "error" methods. Is there an alternative method for trackin ...

What is the best way to update the version numbers of all packages in the package.json file after running the `npm update

Whenever I run npm update, all packages are updated but the version numbers in package.json do not change. The package.json file contains both devDependencies and dependencies, like this: { "name": "test", "version": "1.0.0", "description": "", "m ...

Having trouble toggling webcam video in React/NextJS using useRef?

I have created a Webcam component to be used in multiple areas of my codebase, but it only displays on load. I am trying to implement a toggle feature to turn it on and off, however, I am facing difficulties making it work. Below is the TypeScript impleme ...

apply a visible border to the item that is clicked or selected by utilizing css and vue

I have a list of items that I want to display as image cards with an active blue border when clicked. Only one item can be selected at a time. Below is the code snippet: Template Code <div class="container"> <div v-for="(obj ...

Try experimenting with improperly formatted JSON by utilizing the JerseyInvocation builder

I am currently working on developing an integration test for my dropwizard application to verify that it returns correct error codes. One of the scenarios involves ensuring that if the object being PUT is not deserializable, the application provides an app ...

Is there a way to programmatically parse JSON Data on an iPhone device?

I attempted to decode the JSON Data provided, but encountered difficulties in parsing it correctly. If anyone has insight on this matter, please share your knowledge. Below are snippets of my code and the JSON data: NSString *responseString = [[NSString ...

The value remains constant until the second button is pressed

I have a button that increments the value of an item. <Button bsStyle="info" bsSize="lg" onClick={this.addItem}> addItem: addItem: function() { this.setState({ towelCount: this.state.towelCount - 2, koalaCount: this.state.koalaCount + 2 ...

Refresh the component data according to the vuex state

In order to streamline my workflow, I am developing a single admin panel that will be used for managing multiple web shops. To ensure that I can keep track of which website I am currently working on, I have implemented a website object in my vuex state. Th ...

Encountering difficulties linking to a stylesheet or a script in an HTML file delivered by Express server

Currently, I'm facing the challenge of breaking down my Express app code into multiple files. Unfortunately, I am unable to utilize <link href> or <script src> for linking stylesheets or scripts. Below is the relevant snippet from my inde ...

An issue has arisen with NextJS Link where it is failing to populate an anchor tag

In my React + NextJS project, I am struggling to display a list of products similar to what you would find on an ecommerce category page. Each product is wrapped in a p tag and should link to its corresponding detail page using an anchor a tag. Although t ...

What steps can be taken to address issues with the counting system in a lootbox opening

I am currently developing a virtual loot box simulator and have encountered a challenging issue. My goal is to track the quantity of Normals, Legendaries, Epics, and Rares obtained by the user. However, I am facing a problem where instead of updating the c ...

Error Uncovered: Ionic 2 Singleton Service Experiencing Issues

I have developed a User class to be used as a singleton service in multiple components. Could you please review if the Injectable() declaration is correct? import { Injectable } from '@angular/core'; import {Http, Headers} from '@angular/ht ...